Skip to content

Small Code Samples

Zach edited this page Jan 11, 2024 · 1 revision

State

First the most basic. State is an in-memory value.

Petrify 2024-01-10 at 4 33 01 PM

StoredState

Next is StoredState. It works the exact same as State, but its values are stored in UserDefaults.

Petrify 2024-01-10 at 4 36 47 PM

SyncState

SyncState allows the use of iCloud to sync the state across the user's devices for the app.

Petrify 2024-01-10 at 4 37 21 PM

SecureState

SecureState is the first feature suggested by a user of AppState. It stores String values using the Keychain! Easily store your tokens or sensitive information using it!

Petrify 2024-01-10 at 4 38 25 PM

Dependency

Back to a core feature of AppState.. Dependency is great if you have a service or object you want to share across your app. Dependencies using AppState are initialized once and are initialized just in time when it is first used. Dependencies can also be loaded ahead of time.

Petrify 2024-01-10 at 4 39 46 PM

Slice and Constant

Slice and Constant were introduced in 1.5.0 and allow for fine control of AppState values.

Petrify 2024-01-10 at 4 46 23 PM

OptionalSlice and OptionalConstant

Finally while making this post I found out Optionals were not working as I'd like.. So I implemented OptionalSlice and OptionalConstant to allow for values from optional state. Implemented in 1.6.0.

Petrify 2024-01-10 at 5 33 46 PM