In iOS 7 (and earlier), it became possible to effectively create a “temporary” NSManagedObject with the ability to later add it to the context and save it like this:
NSEntityDescription* entityDescription = [NSEntityDescription entityForName:@"User" inManagedObjectContext:managedObjectContext]; User* user = [[User alloc] initWithEntity:entityDescription insertIntoManagedObjectContext:nil];
Note the nil NSManagedObjectContext parameter. (Mark Marcus S. Zarra's answer to this method here )
However, iOS 8 changed the relationship management, so if you create a temporary object and add a relation to it before setting its context, the connection will be deleted after the restart:
User* user = [User temporaryEntity]; [user addPhotosObject:photo]; [managedObjectContext:insertObject:user]; [managedObjectContext:&error];
This does not affect non-relational objects, but makes it impossible to create temporary objects that have relationships.
Does anyone know how to account for this change and create / use temporary, working NSManagedObject s? Thanks!
-
Also check out this related post on the iOS 8 forum.
source share