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

user970956 picture user970956 · Mar 14, 2015 · Viewed 20.2k times · Source

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?

Thanks

Answer

rintaro picture rintaro · Mar 14, 2015

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
    }
}