Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-16-2010, 07:15 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 33
Default How to retrieve stored reference to an NSManagedObject subclass?

Hi!

I have a NSManagedObject subclass named Tour. I stored the reference to it using this code:

Code:
 prefs = [NSUserDefaults standardUserDefaults];
NSURL *myURL = [[myTour objectID] URIRepresentation];
 NSData *uriData = [NSKeyedArchiver archivedDataWithRootObject:myURL];
 [prefs setObject:uriData forKey:@"tour"];
Now I want to retrieve it. I tried using:

Code:
NSData *myData = [prefs objectForKey:@"tour"];
  NSURL *myURL = [NSKeyedUnarchiver unarchiveObjectWithData:myData];

  TourAppDelegate *appDelegate = (TourAppDelegate *)[[UIApplication sharedApplication] delegate];

  NSManagedObjectID *myID = [appDelegate.persistentStoreCoordinator managedObjectIDForURIRepresentation:myURL];

  if (myID)
  {
  Tour *tempObject = [appDelegate.managedObjectContext objectWithID:myID]; //WARNING
  tour = tempObject;
  }

  if (tour) //instruction...

But it's giving me this warning "Incompatible Objective-c types. Initializing 'struct NSManagedObject *', expected 'struct Tour *'

How can I solve this?
DevSdk is offline   Reply With Quote
Old 03-17-2010, 10:40 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 33
Default

Or is there any other method for saving and retrieving the reference to an nsmanagedobject subclass?

Thanks!
DevSdk is offline   Reply With Quote
Old 10-14-2010, 11:15 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 16
Default

Tour *tempObject = [appDelegate.managedObjectContext objectWithID:myID]; //WARNING

I think your warning comes from that. I think either:

1. Type cast the result: Tour *tempObject = (Tour *)[appDelegate.managedObjectContext objectWithID:myID)

OR

2. Use NSManagedObject: NSManagedObject *tempObject = [appDelegate.managedObjectContext objectWithID:myID];

Just wondering, do you know how to convert NSManagedObject to NSURL?

Hope that helps!
noobdev is offline   Reply With Quote
Reply

Bookmarks

Tags
nsmanagedobject, nsmanagedobjectid, nsurl, nsuserdefaults, reference

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 268
19 members and 249 guests
14DEV, ADY, ArtieFufkin10, ckgni, Dani77, HemiMG, IphoneSdk, jakerocheleau, JasonR, jimbo, MACralik, NSeven, prchn4christ, Rudy, silverwiz, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:56 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0