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

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c# - Making TableLayoutPanel Act Like An HTML Table (Cells That Resize Automatically Around Text) -