我有一个名为 Tour 的 NSManagedObject 子类。我使用以下代码存储了对它的引用:
prefs = [NSUserDefaults standardUserDefaults];
NSURL *myURL = [[myTour objectID] URIRepresentation];
NSData *uriData = [NSKeyedArchiver archivedDataWithRootObject:myURL];
[prefs setObject:uriData forKey:@"tour"];
现在我想找回它。我尝试使用:
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...
但它给了我这个警告“不兼容的Objective-c类型。初始化'struct NSManagedObject *',预期'struct Tour *'
另外,执行时,它给了我这个:由于未捕获的异常'NSObjectInaccessibleException'而终止应用程序,原因:'CoreData无法满足'0x5001eb0的错误
我该如何解决这个问题?