2016-10-09 7 views
-3

MitSchleife durch [[String: Alles]]

let posts = json["posts"] as? [[String: Any]] ?? [] 
print(posts) 

ich

[["id": 1, "title": title 1], ["id": 2, "title": title 2], ["id": 3, "title": title 3], ["id": 4, "title": title 4], ["id": 5, "title": title 5]] 

Wie kann ich Schleife durch diese zu bekommen Wert jedes id und title?

Antwort

3

Iterieren Sie durch posts mit einem for-loop und stellen Sie sicher, dass Sie einen Wert mit guard haben.