Ios – How to combine two SwiftyJSON objects

iosswiftswifty-json

I have a swiftyJSON object that looks like for example:

[{
  "location" : "http://...",
  "img" : "http://...",
  "commentCount" : 0,
  "timestamp" : 1432460217550,
}]

I want to be able to append another swiftyJSON object to it so that it looks like:

[{
  "location" : "http://...",
  "img" : "http://...",
  "commentCount" : 0,
  "timestamp" : 1432460217550,
},
{
  "location" : "http://...",
  "img" : "http://...",
  "commentCount" : 1,
  "timestamp" : 1432460217571,
}
]

I can't use += or .append on swiftyJSON objects. How can I do this?

Best Solution

As you said, swiftyJSON does not have an append functionality.

What you can do is parse the swiftyJSON objects into an array of type anyObject and append them.

let json = JSON(data: data!) 
var JSONObject = JSON(json["content"].arrayObject! + json["content"].arrayObject!)

Data -> NSData Object received from a HTTP request.