user970956 user970956 - 2 years ago 1052
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?


Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download