Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nixzhu committed Mar 2, 2024
1 parent 366b4e8 commit 5da0a1c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,28 @@ extension Mastodon {
}
```

Then, we can initialize a `Mastodon` as follow:
Then, we can decode a `Mastodon` as follow:

```swift
let model = Mastodon.decode(from: jsonString)
let mastodon = Mastodon.decode(from: jsonString)
```

Or

```swift
let model = Mastodon.decode(from: jsonData)
let mastodon = Mastodon.decode(from: jsonData)
```

If you only want to decode a part of the JSON, like `profile`, use the `path` to specify it as follow:

```swift
let profile = Mastodon.Profile.decode(from: jsonData, path: ["proflie"])
```

How about just decode `toots`? It's an array, do it as follow:

```swift
let toots = [Mastodon.Toot].decode(from: jsonData, path: ["toots"])
```

## Swift Macro
Expand Down

0 comments on commit 5da0a1c

Please sign in to comment.