Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
swhitty authored Jul 23, 2023
1 parent de928a2 commit e43426b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ struct User: Codable {
}

// Decode from [String: Any]
let user = try KeyValueCoder().decode(
let user = try KeyValueEncoder().decode(
User.self,
from: ["id": 99, "name": "Herbert"]
)

// Encode to [String: Any]
let dict = try KeyValueCoder().encode(person)
let dict = try KeyValueEncoder().encode(user)
```

RawRepresentable types are encoded to their raw value:

```swift
// Encode to RawValue
let string = try KeyValueCoder().encode(Food(rawValue: "fish"))
let string = try KeyValueEncoder().encode(Food(rawValue: "fish"))
```

Decode values from `Any`:

```swift
let user = try KeyValuDecoder().decode(User.self, from: ["id": 99, "name": "Herbert"])

let food = try KeyValuDecoder().decode(Food.self, from: "fish")
```
## UserDefaults
Store and retrieve any `Codable` type within UserDefaults:

Expand Down

0 comments on commit e43426b

Please sign in to comment.