Possible Duplicate:
Having trouble adding objects to NSMutableArray in Objective C
I have a class with an NSMutabeArray property. In one of the class's methods, I am trying to add objects from another NSArray into this NSMutableArray. (The objects added are NSDictionaries). I have tried a couple of methods for this (specified below) but none of them seems t work, as the objects aren't added into the array (I can see that when I NSLog the count property of the NSMutableArray, which still returns 0.
Why is that, and what is the proper way of adding Items into an NSMutableArray?
Way 1:
NSArray * logItemsTemp = [logParsedData objectForKey:@"log"]; //items to add, NSlooged the count property and there are 3 items
[[self logItemsArray] addObjectsFromArray:logItemsTemp]; //adding items to the NSMutableArrayProperty logItems array - unsuccessful
Way 2:
NSArray * logItemsTemp = [logParsedData objectForKey:@"log"]; //items to add, NSlooged the count property and there are 3 items
for (int i = 0; i<[logItemsTemp count]; i++) {
[logItemsArray addObject:[logItemsTemp objectAtIndex:i]]; //adding items to the NSMutableArrayProperty logItems array - unsuccessful
}
EDIT:
NSArray * logItemsTemp = [logParsedData objectForKey:@"log"];
if ([self logItemsArray] == NULL) {
self.logItemsArray = [NSMutableArray new];
NSLog(@"%@",logItemsTemp);
}
[[self logItemsArray] addObjectsFromArray:logItemsTemp];