Reputation: 28258
I am loading json into a list of objects I am adding to a NSMutableArray which seems to be working fine except for the fact that I can't seem to keep the array around to access later.
This is my .h:
@interface ClientController : UITableViewController {
NSMutableData *responseData;
NSMutableArray *ClientList;
}
@property (nonatomic, retain) NSMutableArray *ClientList;
In my .m I add:
@synthesize ClientList;
later I have a method that populates it (Client is a class I have as well):
/* some code that parses the Json */
for (int i = 0; i < [items count]; i++)
{
Client* client = [[Client alloc] init];
client.CompanyName = [[items objectAtIndex:i] objectForKey:@"CompanyName"];
client.ClientID = [[items objectAtIndex:i] objectForKey:@"ClientID"];
[ClientList addObject:client];
NSLog(@"CompanyName: %@\n", client.CompanyName);
[client release];
}
Console shows me that is is working properly because I see the data I expect BUT when I do this I get a null value:
NSLog(@"Clients Count: %@\n", [ClientList count]);
I need to loop though this to build my table - so what am I missing here?
Upvotes: 0
Views: 172
Reputation: 21903
Gotta initialize your ClientList, thusly:
-(void)viewDidLoad
{
self.ClientList = [NSMutableArray array];
}
Otherwise self.ClientList is a nil pointer, and as a result, [self.ClientList addObject:]
is a silent no-op, as is [self.ClientList count]
.
By the way, the name "clientList" would probably be preferable. We like our variables to start lower-cased in Obj-C.
Upvotes: 1