• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
managedObjectIDForURIRepresentation returning wrong NSManagedObjectID
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: managedObjectIDForURIRepresentation returning wrong NSManagedObjectID
      • From: Mike Abdullah <email@hidden>
    • Re: managedObjectIDForURIRepresentation returning wrong NSManagedObjectID
      • From: Ben <email@hidden>
  • Prev by Date: Re: NSOutlineView cell editing behavior
  • Next by Date: Re: managedObjectIDForURIRepresentation returning wrong NSManagedObjectID
  • Previous by thread: Re: Optimal height for WebView
  • Next by thread: Re: managedObjectIDForURIRepresentation returning wrong NSManagedObjectID
  • Index(es):
    • Date
    • Thread