A simple guess would be because when we recently add the object we do not know or do not have certain information to create the permanent ID.
Fine.
Then I read this:
obtainPermanentIDsForObjects:error:
Converts to permanent IDs the object IDs of the objects in a given array.
– (BOOL)obtainPermanentIDsForObjects:(NSArray )objects error:(NSError *)error
This method converts the object ID of each managed object in objects to a permanent ID. Although the object will have a permanent ID, it will still respond positively to isInserted until it is saved. Any object that already has a permanent ID is ignored.
Any object not already assigned to a store is assigned based on the same rules Core Data uses for assignment during a save operation (first writable store supporting the entity, and appropriate for the instance and its related items).
Special Considerations
Okay, so we got temporary ID until we save the NSManagedObject. However
Saving the managedObjectContext will not update the ID of the NSManagedObjects. it remain the same as this code shows:
PO([Catalogs convertEachElementToAnother:(id)^(id element) {
BGCatalogData * data = (BGCatalogData*) element;
NSManagedObjectID * theObjectID= data.objectID;
return theObjectID;
}]);
NSError * error;
BOOL saveSuccesfully = [[BGMDCRManagedObjectContextThreadHandler managedObjectContext] save:&error];
PO([Catalogs convertEachElementToAnother:(id)^(id element){
BGCatalogData * data = (BGCatalogData*) element;
NSManagedObjectID * theObjectID= data.objectID;
return theObjectID;
}]);'
Note to mod: I can’t convert the above into code
Which results in:
[Catalogs convertEachElementToAnother:(id)^(id element){ BGCatalogData * data = (BGCatalogData*) element; NSManagedObjectID * theObjectID= data.objectID; return theObjectID; }]: (
"0x888a340 <x-coredata:///BGCatalogData/t084E0F43-A129-4023-8190-2962D8D0930A603>",
"0x888d670 <x-coredata:///BGCatalogData/t084E0F43-A129-4023-8190-2962D8D0930A609>",
"0x888ed50 <x-coredata:///BGCatalogData/t084E0F43-A129-4023-8190-2962D8D0930A615>",
"0x888f690 <x-coredata:///BGCatalogData/t084E0F43-A129-4023-8190-2962D8D0930A621>"
)
2012-11-16 15:33:28.489 BadgerNew[26871:1d03] [Catalogs convertEachElementToAnother:(id)^(id element){ BGCatalogData * data = (BGCatalogData*) element; NSManagedObjectID * theObjectID= data.objectID; return theObjectID; }]: (
"0x888a340 <x-coredata:///BGCatalogData/t084E0F43-A129-4023-8190-2962D8D0930A603>",
"0x888d670 <x-coredata:///BGCatalogData/t084E0F43-A129-4023-8190-2962D8D0930A609>",
"0x888ed50 <x-coredata:///BGCatalogData/t084E0F43-A129-4023-8190-2962D8D0930A615>",
"0x888f690 <x-coredata:///BGCatalogData/t084E0F43-A129-4023-8190-2962D8D0930A621>"
)
We can give objects permanent ID by calling obtainPermanentIDsForObjects BEFORE the object is saved.
So why IOS bother waiting till saving to give permanent ID? Why not right away?
because CoreData has to manipulate the underlying Persistant Store to ‘block’ the permanentIDs for other objects (increment a counter for example). If you do not need the permanentIDs before saving its an unnecessary and propably slow thing to do (you could use your items only temporary and never save it)