Reputation: 83
for(int i=0;i<[promotionArr count];i++)
{
// NSLog(@"ok");
Promotion *prom = [[Promotion alloc]init];
prom.pName=[[promotionArr objectAtIndex:i] objectForKey:@"name"];
prom.pUrl=[[promotionArr objectAtIndex:i] objectForKey:@"url"];
prom.pDescription=[[promotionArr objectAtIndex:i] objectForKey:@"description"];
[promMUAraay addObject:prom];
NSLog(@"number of elements : %d",[promMUAraay count]);
}
But the number of element is always 0 . I haven't do @synthetise for the NSMutableArray , xcode tell me that i can't .I just do this in my .h
NSMutableArray *promMUAraay;
It's that the problem ?
Upvotes: 0
Views: 169
Reputation: 69027
You should initialize your NSArray before accessing it. That is, in your .m file, in your -init
method, you should have some code like this:
promMUAraay = [[NSMutableArray alloc] init.......];
For all the options you have initializing an NSArray, see the NSArray reference.
As to your attempt at syntethizing
the array, the @synthetize
keyword is used to automatically create definitions for setter/getter methods to your array (provided you have a corresponding @property
declaration in your interface). This does not change things in that you would all the same need to initialize your NSArray in the init method of your class. The only thing is that you could thereafter refer your variable using the dot-notation: self.promMUAraay
.
Upvotes: 1
Reputation: 969
Have you remembered to alloc, init the array?
NSMutableArray *array = [[NSMutableArray alloc] init];
Do this before you use the array.
Upvotes: 6