0
使用核心數據,我可以在內存中保存和獲取對象;然而,當我重新啓動我的應用程序(在模擬器中)並獲取結果時,對象被提取但所有屬性均爲零。我已將所有協議方法包含在我的appdelegate中,並初始化了我的managedObjectContext,如下所示:iOS核心數據持久性重新啓動應用程序後
managedObjectContext = [self managedObjectContext];
在 - (BOOL)申請:(UIApplication的*)應用程序didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions
這是我得到的日誌什麼...
正確: 擷取結果日誌(應用程序未重新啓動) - >名稱:新條目!!!!
錯誤: 擷取結果日誌(應用程序重新啓動) - >名稱:(空) - 但是,對象仍然在persistantStore
存在-
//Save entry
Entry *entry = (Entry *)[NSEntityDescription insertNewObjectForEntityForName:@"Entries" inManagedObjectContext:managedObjectContext];
[entry setTitle:@"new entry!!!!"];
NSError *error;
if(![managedObjectContext save:&error]){
NSLog(@"SAVE ERROR!!!");
}
//Fetch entry
NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Entries" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *info in fetchedObjects) {
NSLog(@"Name: %@", [info valueForKey:@"title"]);
}