So I have this NSArray with NSDictionaries inside.
As you can see in the code there are actually two very equal for loops (don't mind why).
If you see the log, the key scheduleID in the first object in the second loop is suddenly nil...
I have no clue whatsoever how this is even possible. The object (NSDictionary) itself is not nil. I am using ARC.
UILocalNotification *mergedNotification = [notificationsWithEqualFireDates objectAtIndex:0];
if ([notificationsWithEqualFireDates count] > 1) {
NSMutableArray *mergedUserInfo = [[NSMutableArray alloc] init];
for (UILocalNotification *ln in notificationsWithEqualFireDates) {
NSLog(@"Hmmm... %@", [ln.userInfo objectForKey:@"scheduleID"]);
[mergedUserInfo addObject:ln.userInfo];
}
NSDictionary *mergedUserInfoDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:mergedUserInfo,@"array", nil];
mergedNotification.userInfo = mergedUserInfoDictionary;
}
for (UILocalNotification *tempNotification in notificationsWithEqualFireDates) {
NSManagedObject *managedObject = [NSEntityDescription insertNewObjectForEntityForName:@"RegisteredNotifications" inManagedObjectContext:newMoc];
[managedObject setValue:tempNotification.fireDate forKey:@"fireDate"];
[managedObject setValue:[tempNotification.userInfo objectForKey:@"dateTimeOriginal"] forKey:@"dateTimeOriginal"];
[managedObject setValue:[tempNotification.userInfo objectForKey:@"scheduleID"] forKey:@"scheduleID"];
NSLog(@"Saving schedule: %@", [tempNotification.userInfo objectForKey:@"scheduleID"]);
}

UPDATE I was able to fix this issue by using the copy method:
UILocalNotification *mergedNotification = [[notificationsWithEqualFireDates objectAtIndex:0] copy];
Can somebody please explain why this was happening and why I need this copy method. I would think that assigning an object from an NSArray to a variable would be to create a memory location, init it and then copy the value from the place in the array to the variable...