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

后端 未结 6 1003
梦谈多话
梦谈多话 2021-01-08 00:55

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!)

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-08 01:11

    Declare you main JSON Array as :

    var data:[JSON] = []
    

    If the data source is any other object (like realm) loop over it using for loop But if the data source is another JSON Array perform :

    func setData(){
            data = []
            if let items = sourceData.array {
                for item in items {
                  data.append(item)
                }
            }
            collectionView.reloadData()
        }
    

提交回复
热议问题