Tometoyou Tometoyou - 6 months ago 105
Swift Question

How to combine two SwiftyJSON objects

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?

Answer

Victor's answer didn't work for me. But I solved the question by putting my JSON object, data, into an array like this:

var data: [JSON] = []

and using the following code:

self.data = self.data + JSON["content"].arrayValue
Comments