So I have this method in which I query some Singleton class to get data, I add it to my mutable array called profile details, but It doesn't get added, if i add it to a temp array first and then use that to assign it to my profile details array it works? What's happening here?
//Property declaration
@property (nonatomic, strong) NSMutableArray *profileDetails;
//Method definition
- (void) getAllProfiles : (NSArray *) profiles
{
if (_myHealthDetailService == nil) {
self.myHealthDetailService = [[MyHealthDetailService alloc] init];
}
if (profiles) {
if (self.currentProfileCounter < [profiles count]) {
MyHealth *profile = [profiles objectAtIndex:self.currentProfileCounter];
[self.myHealthDetailService requestForMyHealthDetailWithHealth:profile completion:^(NSArray *healths) {
self.currentProfileCounter = self.currentProfileCounter + 1;
if (healths) {
NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:healths.count];
for (MyHealth *profile in healths) {
NSLog(@"Adding Proile: %@",profile);
[self.profileDetails addObject:profile];
[tempArray addObject:profile];
NSLog(@"Proile details array after adding %@ profile is: %@",profile, self.profileDetails);
NSLog(@"Temp Proile details array after adding %@ profile is: %@",profile, tempArray);
}
self.profileDetails = tempArray;
NSLog(@"Proile details array after copying is: %@",self.profileDetails);
}
DashboardHealthCell_iPad *cell = (DashboardHealthCell_iPad *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForItem:DashboardRow_iPadTypeHealth inSection:0]];
NSLog(@"Proile details array is: %@",self.profileDetails);
[cell populateMyHealthProfiles:self.profileDetails];
} failureBlock:^(NSError *error) {
}];
}
}
}
Relevant NSLog output:
2014-03-12 12:45:58.144 CHM[9768:70b] Proile details array after adding <MyHealth: 0xd562ce0> profile is: (null)
2014-03-12 12:45:58.144 CHM[9768:70b] Temp Proile details array after adding <MyHealth: 0xd562ce0> profile is: (
"<MyHealth: 0xd562270>",
"<MyHealth: 0xd5629e0>",
"<MyHealth: 0xd562ce0>"
)
2014-03-12 12:45:58.144 CHM[9768:70b] Proile details array after copying is: (
"<MyHealth: 0xd562270>",
"<MyHealth: 0xd5629e0>",
"<MyHealth: 0xd562ce0>"
)