ios - Why is array empty after appending object to it -
i working in tableviewcontroller trying fill data plist.
i declared @ top:
var studentsarray:array<studentdata>?
and doing following in function loads plist:
var path = nsbundle.mainbundle().urlforresource("students", withextension: "plist") let tmparray = nsarray(contentsofurl: path!) studentdict in tmparray!{ let name = studentdict["name"]as! string let dateofbirth = studentdict["dateofbirth"] as! nsdate let regular = studentdict["regular"] as! bool let photofilename = studentdict["photofilename"] as! string let data = studentdata(name : name, dateofbirth: dateofbirth, regular : regular, photofilename: photofilename) self.studentsarray?.append(data) println(studentsarray!.count) }
i tried logging properties of object, being filled in, goes wrong @ .append
, somehow won't that. array's count remains 'nil' when logged.
i'm kind of lost here! appreciated.
doesn't initializing studentsarray anywhere. make sure that. record, array.count should 0 if array empty, not nil. if seeing nil means array nil (aka didnt initialize it).
Comments
Post a Comment