ios - Swift run function before collectionView's functions -


i have got function in swift code

  func myfunc(){      let jsondata2 = try jsonserialization.jsonobject(with: data, options: []) as! [[string: any]      self.comments = jsondata2   } 

and in collectionview's numberofitemsinsection function have this

return comments.count 

what need first run myfunc , after run other collectionview's functions.i tried putting myfunc() right @ begginning of viewdidload(),but didn't worked.

you need define comments array empty, , load relevant data in viewwillappear

class yourviewcontroller: uiviewcontroller {       var comments : [yourobjects] = []       override func viewwillappear(_ animated: bool) {         super.viewwillappear(animated)         self.myfunc()       }      func myfunc(){          let jsondata2 = try jsonserialization.jsonobject(with: data, options: []) as! [[string: any]          self.comments = jsondata2          dispatchqueue.main.async{           self.collectionview.reloaddata() //reload data after          }          }  } 

hope helps


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -