i have this code in my .h:
@property (nonatomic, retain) NSArray *arrayData;
What is the difference between:
self.arrayData = [[NSArray alloc]initWithObjects:@"date",@"trip",nil];
and:
arrayData = [[NSArray alloc]initWithObjects:@"date",@"trip",nil];
and what should i use and how to release the arrayData variable.
Thanks
The difference is that using
self.arrayData = ...retains the array. You should release it usingself.arrayData = nil;.The code you
havehad here doesn’t work, forinitalone doesn’t allocate an array. You could useTo allocate and initialize the array.
ps the
arrayWithObjectsreturns an allocated and autoreleased object. That means that the object will vanish if you don’t retain it. So useself.arrayData = ...to do so.The equivalent with alloc/init/autorelease would read: