iOS/Swift/Parse - Struct not storing data -
i'm having trouble storing data parse in struct. have set uitableviewcontroller use separate struct file get/manage data parse. struct gets data parse (confirmed using println), when try , reference data populate table, struct empty again. below 2 files (several methods omitted try , make more concise here). had working correctly when used separate class (instead of struct) parse data, have since decided struct better needs. can spot going wrong struct? many thanks.
console output
resultsarray.count = 45 filled objectlist.count = 1 objects @ index0.count = 45 testprint objectlist.count = 0
uitableviewcontroller
import uikit import parse class exercisemuscletypetableviewcontroller: uitableviewcontroller { // mark: variables var citadel: citadel = citadel() // mark: ibactions @ibaction func refreshbutton(sender: uibarbuttonitem) { citadel.testprint() } // mark: override override func viewdidload() { super.viewdidload() citadel = citadel(parseclassname: "exerciselist", orderedby: "muscleprimary") } }
struct connecting parse
import foundation import parse struct citadel { // mark: properties var objectlist: [[pfobject]] = [[pfobject]]() var sectionheaders: [string] = [string]() var parseclassname: string? var userid: string? // mark: methods func testprint() { println("testprint, objectlist.count = \(self.objectlist.count)") } // mark: init init(parseclassname: string, orderedby: string) { // set structure's properties self.parseclassname = parseclassname self.objectlist = [[pfobject]]() self.sectionheaders.removeall(keepcapacity: true) if let id = pfuser.currentuser()!.objectid { self.userid = id } // format query data parse var query = pfquery(classname: parseclassname) query.orderbyascending(orderedby) query.findobjectsinbackgroundwithblock { (queryresult: [anyobject]?, error: nserror?) -> void in if let resultsarray = queryresult as? [pfobject] { println("resultsarray.count = \(resultsarray.count)") self.objectlist = [resultsarray] println("filled objectlist.count = \(self.objectlist.count)") println("objects @ index0.count = \(self.objectlist[0].count)") } } } }
it looks me issue because you're initializing struct variable here: var citadel = citadel()
, you're reinitializing in viewdidload
. try declaring var
var citadel: citadel?
, initialize in viewdidload
, see if helps out.
Comments
Post a Comment