Repository navigation
What's Changed
Added
Application.didFailToPersist(_:), an overridable method that is called when aFileStatefile cannot be decoded, written or deleted, or when aStoredStateorSyncStatevalue cannot be encoded. It receives anApplication.PersistenceFailurewith 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. AFileStatethat was never written is not reported. An unreadable file is reported once, not on every read.- An iOS demo app in
Examples/DemoAppwith UI tests, and an iOS CI job that runs them and the unit tests inside the app.
Fixed
- A write to a
StateorFileStatemade 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 aUUID()orDate()initial now reads the same value every time, andreset()restores that first value.- A write through
@AppState,@StoredState,@FileState,@SecureState,@SyncState,@Sliceor@OptionalSliceon anObservableObjectthat declares its ownobjectWillChangeis stored. It used to be dropped. StoredStateno longer crashes withNSInvalidArgumentExceptionon a value thatJSONEncoderrejects, such as a struct holdingDouble.nan. The write is logged and ignored, and the previous value stays.- A
FileStatecreated withisBase64Encoded: falsereads back values whose JSON text is also valid Base64, such astrueor1234. 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 whenicloudStorewas loaded before the promotion.FileManager.defaultFileStatePathis 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
DependencyOverriderestores the dependency, as theoverridedocumentation says. Before, onlycancel()did. Code that discarded the token and relied on the override staying must now keep the token, or useApplication.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