amjad amjad - 6 months ago 22x
Swift Question

load from json array into object array swift

I have array of user

var User:[User] = []

I want by alamofire and swiftyjson get info from
I know how to request and then i have array of json

how i can make loop through json array and create object of user then append in array

I think my problem with loop , this is from swifty json page

for (index,subJson):(String, JSON) in json {
//Do something you want

how i can use it in my App?


You can use similar following code

for (_, subDataJSON): (String, JSON) in dataJSON {
  let u = User() = subDataJSON["name"].stringValue = subDataJSON["id"].intValue = subDataJSON["active"].boolValue

Parse your data json in loop then at the end of loop append single user object to global class User array like that.

Then use your class scoped User array like as you want.