managedObjectIDForURIRepresentation returning wrong NSManagedObjectID
managedObjectIDForURIRepresentation returning wrong NSManagedObjectID
- Subject: managedObjectIDForURIRepresentation returning wrong NSManagedObjectID
- From: Ben <email@hidden>
- Date: Fri, 08 Feb 2013 09:06:53 +0000
I'm confused by the following code. What I'm trying to do is store a reference in a DogManagedObject transformable property, to a CatManagedObject, then retrieve the Cat from the Dog at a later date.
However, when I log the output I get a class of 'Dog' rather than 'Cat'.
Any ideas?
//add the NSData
NSURL *uri = [[catManagedObject objectID] URIRepresentation];
NSData *uriData = [NSKeyedArchiver archivedDataWithRootObject:uri];
//selectedInstrument is a transformable property
dogManagedObject.selectedInstrument = uriData;
[_managedObjectContext save:&error];
//retrive the NSData
NSData * data = (NSData *) dogManagedObject.selectedInstrument;
NSURL *uri2 = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSManagedObjectID *moID = [_persistentStoreCoordinator managedObjectIDForURIRepresentation:uri2];
CatManagedObject * cat = (CatManagedObject *)[_managedObjectContext objectWithID:moID];
NSLog(@"log %@", cat);
Ouputs....
log <DogManagedObject: 0x7853840> (entity: DogManagedObject; id: 0x7853f90 <x-coredata://D9B53F16-BE02-4125-ACF1-ABF50835F296/DogManagedObject/p1> ; data: {
cats = "<relationship fault: 0x784f670 'cats'>";
selectedCat = "<62706c69 73743030 d4010203.... etc
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden