json - Swift 3 - Can not use array made Alamofire request -


hoping can me! working on 1 while now. problem can not use data in uitableviewcontroller received alamofire request. request want put in struct in alamofire request. in end can not use information put in array. looks array keeps empty outside function. tried make closure, receive table in viewdidload request, still can not use outside one.

i have structure in swift file called section:

struct mijnproducten {     var productname : string!     var productdesc : string!     var expanded : bool!      init(productname: string, productdesc: string, expanded: bool)     {         self.productname = productname         self.productdesc = productdesc         self.expanded = false     }  } 

uitableviewcontroller looks this:

array made:

var mijnproducten01 = [mijnproducten]() 

below fund alamofire request:

func getuserproperty(completion: @escaping ([mijnproducten]) -> void) {      alamofire.request(url_user_property, method: .post, encoding: jsonencoding.default) .responsejson(completionhandler: { response -> void in             //getting json value server productid, tagid, status, productimage             switch response.result {              case .success(let value):                 let jsonarray = json(value)                 print(value)                 var mijnproducten01 : [mijnproducten] = []                  (index, dict) in jsonarray {                     let thisobject = mijnproducten(productname: dict["productname"].string!, productdesc: dict["productdesc"].string!, expanded: false )                     mijnproducten01.append(thisobject) }                  completion(mijnproducten01)              case .failure(let error):                 print(error)                 completion([])             }         self.tableview.reloaddata()     }) } 

in vieddidload:

override func viewdidload() {         super.viewdidload()       getuserproperty(completion: { data in        self.mijnproducten01 = data         print("yess", self.mijnproducten01)})         print("nooo",mijnproducten01) } 

there printed information in yesss print, not in nooo.

in end goal substract information array , use in tablecell , header.

when put in header function:

override func tableview(_ tableview: uitableview, viewforheaderinsection section: int) -> uiview? {        let header = tableview.dequeuereusableheaderfooterview(withidentifier: "expandableheaderview") as! expandableheaderview         header.custominit(productname: mijnproducten01[mijnproducten].productname, productdesc: mijnproducten01[mijnproducten].productdesc, section: section, delegate: self)         //print("print", mijnproducten01)         return header     } 

i error in: mijnproducten01[mijnproducten].productname.

i hope 1 can on way!

thanks! found solution, maybe not best way works. added ui label in rows. ui label gets assigned value used in header. in end made uilabel not visible. in way every row in section wright header description can in didselectrow!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -