Skip to content

3.1.0

Latest

Choose a tag to compare

@0xLeif 0xLeif released this 16 Nov 23:25
69d692c

What's Changed

  • Add an iOS demo app with UI tests and an iOS CI job by @0xLeif in #159

Added

  • Application.didFailToPersist(_:), an overridable method that is called when a FileState file cannot be decoded, written or deleted, or when a StoredState or SyncState value cannot be encoded. It receives an Application.PersistenceFailure with the kind of state, the operation, the state's key and the underlying error. The default implementation does nothing, and logging is unchanged, so an app that does not override it behaves as before. A FileState that was never written is not reported. An unreadable file is reported once, not on every read.
  • An iOS demo app in Examples/DemoApp with UI tests, and an iOS CI job that runs them and the unit tests inside the app.

Fixed

  • A write to a State or FileState made right after its first read is no longer undone. Outside XCTest on Apple platforms the getter filled the cache from a deferred task, which ran after the write and put the older value back. The cache is now filled before the getter returns.
  • state(initial:) evaluates its initial value once per scope, as documented, instead of on every access. A state with a UUID() or Date() initial now reads the same value every time, and reset() restores that first value.
  • A write through @AppState, @StoredState, @FileState, @SecureState, @SyncState, @Slice or @OptionalSlice on an ObservableObject that declares its own objectWillChange is stored. It used to be dropped.
  • StoredState no longer crashes with NSInvalidArgumentException on a value that JSONEncoder rejects, such as a struct holding Double.nan. The write is logged and ignored, and the previous value stays.
  • A FileState created with isBase64Encoded: false reads back values whose JSON text is also valid Base64, such as true or 1234. They used to read as the initial value after a relaunch.
  • Application.promote(to:) keeps the promoted application registered for iCloud key-value store changes when icloudStore was loaded before the promotion.
  • FileManager.defaultFileStatePath is no longer percent-encoded. A documents path with a space or a non-ASCII character pointed at a directory that does not exist.
  • Overrides of the same dependency can end in any order. Ending an older override while a newer one was alive used to put the older value back at once, and left a stale override in place after both had ended. The dependency is now the newest override still alive, and the original once none is.

Changed

  • Releasing a DependencyOverride restores the dependency, as the override documentation says. Before, only cancel() did. Code that discarded the token and relied on the override staying must now keep the token, or use Application.promote(_:with:) for a permanent replacement.

Documentation

  • The restricted state example in Advanced Usage keeps its ID in a constant. With UUID() inside the computed property the state never kept a value.
  • The dependency example in State and Dependency Usage compiles in Swift 6 mode.

Full Changelog: 3.0.2...3.1.0