objective c - Why does my array stay empty? -


hi i'm objc noob. have problem filling nsmutablearray objects.

for(id p in tmparray){     person *person = [[person alloc] init];     person.usrname = p;     [persons addobject:person]; // after line persons                                 // array still empty     [person release]; } 

persons property nsmutablearray , problem it's empty. release of person object or have instanciated wrong?

you need initialize array in -init method, this:

nsmutablearray *array = [[nsmutablearray alloc] init]; self.persons = array; // automatically retained                        // because you're using property [array release]; // alloced - release 

don't forget release it:

-(void)dealloc {      self.persons = nil; // previous value of property 'persons' released      [super dealloc]; } 

Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -