I try to get stuff from the web in a different thread.
- I used a new managedobject context. I set the managedobjectcontext of the main thread as the parent.
- I save the new managedobject context
- I collect the managedobjectid (which should now be permanent)
Well, the problem is it's not permanent. The objectID
of the managedObjectModel
remain the same.
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;
}]);
Here, PO is similar with NSLog
. ConvertEachElementToAnother
will simply go through the array and convert each element to the array to something else. That something else is returned in another array.
Result:
[Catalogs convertEachElementToAnother:(id)^(id element){ BGCatalogData * data = (BGCatalogData*) element; NSManagedObjectID * theObjectID= data.objectID; return theObjectID; }]: (
"0x8d26df0 <x-coredata:///BGCatalogData/tA2D6533A-00E2-4BD7-8A68-49944BC4DD18603>",
"0x8d24fe0 <x-coredata:///BGCatalogData/tA2D6533A-00E2-4BD7-8A68-49944BC4DD18609>",
"0x8d24930 <x-coredata:///BGCatalogData/tA2D6533A-00E2-4BD7-8A68-49944BC4DD18615>",
"0x8d23520 <x-coredata:///BGCatalogData/tA2D6533A-00E2-4BD7-8A68-49944BC4DD18621>"
)
(lldb) po error
(NSError *) $1 = 0xb0102d28 [no Objective-C description available]
2012-11-16 15:57:18.763 BadgerNew[29395:1d03] [Catalogs convertEachElementToAnother:(id)^(id element){ BGCatalogData * data = (BGCatalogData*) element; NSManagedObjectID * theObjectID= data.objectID; return theObjectID; }]: (
"0x8d26df0 <x-coredata:///BGCatalogData/tA2D6533A-00E2-4BD7-8A68-49944BC4DD18603>",
"0x8d24fe0 <x-coredata:///BGCatalogData/tA2D6533A-00E2-4BD7-8A68-49944BC4DD18609>",
"0x8d24930 <x-coredata:///BGCatalogData/tA2D6533A-00E2-4BD7-8A68-49944BC4DD18615>",
"0x8d23520 <x-coredata:///BGCatalogData/tA2D6533A-00E2-4BD7-8A68-49944BC4DD18621>"
)
Here, the objectID
of the NSManagedObject
doesn't change at all.
I checked that error is nil. The code works without problem. Only ocassionally. I am just curious why the ID doesn't change after saving. The data is quite big. Actually this is the first time I do this. Should I expect data.ObjectID to change while saving? The reason I asked is because the parent of the managedObject context is a managedObject context and the persistent store is "in memory"