From 5da0a1c168eca589099b7f62bbbd5d558a7f6010 Mon Sep 17 00:00:00 2001 From: nixzhu Date: Sat, 2 Mar 2024 15:54:43 +0800 Subject: [PATCH] update readme --- README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3f368d6..afcfb42 100644 --- a/README.md +++ b/README.md @@ -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