user970956 user970956 - 11 months ago 805
Swift Question

How to append new data to an existing JSON array(swiftyJSON)

I have an array of SwiftyJson data that I have declared and filled it with data .The code I'm using to fill the hoge array is this :

self.hoge = JSON(data: data!)

but I need to append new swiftyJSON data to this hoge array .I noticed hoge array doesn't have append property . How should I do that?



SwiftyJSON does not have append or extend functionality.

You can:

self.hoge = JSON(self.hoge.arrayObject! + JSON(data: newData).arrayObject!)

But I recommend to declare self.hoge as [JSON]

var hoge:[JSON] = []

func readMoreData() {

    let newData: NSData = ...

    if let newArray = JSON(data:newData).array {
        self.hoge += newArray