Unable to add NSmutableDictionary in NSmutableArray, activitiesFeedArray is a mutable array and initialized in header file.
NSMutableDictionary *dummyitem = [[NSMutableDictionary alloc]init];
NSMutableDictionary *dummyitem2 = [[NSMutableDictionary alloc]init];
NSMutableDictionary *dummyitem3 = [[NSMutableDictionary alloc]init];
[dummyitem setObject:@"No Data Found" forKey:@"text"];
[dummyitem2 setValue:dummyitem forKey:@"Title"];
[dummyitem3 setObject:dummyitem2 forKey:@"ItemInfo"];
NSLog(@"%@",dummyitem3);
//dummyitem3 logs correct value here
if ([activitiesFeedArray count] == 0)
{
NSLog(@"%@",dummyitem3);
//dummyitem3 logs correct value here
[activitiesFeedArray addObject:dummyitem3];
NSLog(@"%@",activitiesFeedArray);
//activitiesFeedArray logs null value here
}
Viewdid load
(void)viewDidLoad
{
[super viewDidLoad];
activitiesFeedArray = [[NSMutableArray alloc]init];
}
Header File
@interface SearchViewController : UIViewController <UISearchBarDelegate ,UITableViewDelegate , UITableViewDataSource>
{
NSMutableArray *activitiesFeedArray;
}
@end
If this is the only code you have, then it should work fine and NSLog of your NSMutableArray should not return nil. I copied and pasted your code on my XCode and it works perfectly. You must be doing something somewhere else in your code to alter NSMutableArray.
If you are curious what I did to prove that your code works, I created a simple UIViewController with one button in it. I then created a UIViewController class and literally copied your code in the header file and the implementation file. I declared the NSMutableArray in the header file and initialized it in viewdidload (I copied and pasted them as is). I also put the rest of your NSMutableDictionary code in the viewDidLoad and it produced sensible results. The NSMutableArray log shows that it contains the correct data.
Sometimes it helps to do a clean build but as far as I can tell you, your code is correct and should work.
By the way, I have IOS5 and XCode 4.2.