Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires authored Jan 10, 2024
1 parent f98dc0e commit ac245b5
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,24 @@ The following types are supported by default for use with `@WrappedDefault`.
- `Codable` types

> [!WARNING]
> If you are storing custom `Codable` types and using the default implementation of `UserDefaultsSerializable` provided by `Foil`, then **you must use the optional variant of the property wrapper**, `@WrappedDefaultOptional`. This will allow you to make breaking changes to your `Codable` type (e.g., adding or removing a property). Alternatively, you can provide a custom implementation of `Codable` that supports migration, or provide a custom implementation of `UserDefaultsSerializable`.
>
> **Example:**
>
> ```swift
> // Do this
> @WrappedDefaultOptional(key: "user", userDefaults: store)
> var user: User?
>
> // Do NOT this
> @WrappedDefault(key: "user", userDefaults: store)
> var user = User()
> ```
> If you are storing custom `Codable` types and using the default implementation of `UserDefaultsSerializable` provided by `Foil`, then **you must use the optional variant of the property wrapper**, `@WrappedDefaultOptional`. This will allow you to make breaking changes to your `Codable` type (e.g., adding or removing a property). Alternatively, you can provide a custom implementation of `Codable` that supports migration, or provide a custom implementation of `UserDefaultsSerializable` that handles encoding/decoding failures. See the example below.
**Codable Example:**
```swift
// Note: uses the default implementation of UserDefaultsSerializable
struct User: Codable, UserDefaultsSerializable {
let id: UUID
let name: String
}

// Yes, do this
@WrappedDefaultOptional(key: "user")
var user: User?

// NO, do NOT this
@WrappedDefault(key: "user")
var user = User()
```

## Additional Resources

Expand Down

0 comments on commit ac245b5

Please sign in to comment.