ios - Swift Array Objects Disapearing -
i'm trying initialise objects in for-loop, add them array , access them later. what's happening objects become unreachable reason , array empty.
here's simplified version of code i'm implementing:
class classa { var : [customtype] init() { self.a = [] } func doloop(jsonresults: nsdictionary) { // breakpoint 1: self.a empty (on first run) should be. jsonresult in jsonresults { var j = customtype(jsonresult["key1"], jsonresult["key2"]) self.a.append(j) // breakpoint 2: prints self.a each j being correctly appended } } func retrieveitem() -> customtype { // breakpoint 3: self.a empty array! return self.a[0] } }
doloop called first, , retrieveitem called. have checked doloop runs before 'retrieveitem' called.
according code, if a
empty, jsonresults
empty.
please check length of jsonresults
Comments
Post a Comment