amjad amjad - 2 years ago 102
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download