![]() The key name must be ASCII, not start with and cannot contain a dot (. You declare the defaults keys upfront with a type and default value. If a type conforms to both NSSecureCoding and Codable, then Codable will be used for the serialization. You can easily add support for any custom type. For more examples, see Tests/DefaultsTests. For example, ].įor more types, see the enum example, Codable example, or advanced Usage. Requires Xcode 14.1 or later Support typesĭefaults also support the above types wrapped in Array, Set, Dictionary, Range, ClosedRange, and even wrapped in nested types. Comes with a convenience SwiftUI Toggle component.Īdd in the “Swift Package Manager” tab in Xcode. ![]() Easy to add support for your own custom types.Supports many more types, even Codable.You also define the default values in a single place instead of having to remember what default value you used in other places.Customizable: You can serialize and deserialize your own type in your own way.īenefits over You define strongly-typed identifiers in a single place and can use them everywhere.Debuggable: The data is stored as JSON-serialized values.NSSecureCoding support: You can store any NSSecureCoding value.Codable support: You can store any Codable value, like an enum.SwiftUI: Property wrapper that updates the view when the UserDefaults value changes.Strongly typed: You declare the type and default value upfront.It's used in production by all my apps (1 million+ users). It uses UserDefaults underneath but exposes a type-safe facade with lots of nice conveniences. Store key-value pairs persistently across launches of your app.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |