2015-10-02 46 views
1

我使用MagicalRecord,我不能明白和檢索你剛纔保存MagicalRecord - 檢索最後插入的記錄id

Items *item = [Items MR_createEntity]; 
item.ref_user = ref_user; 
[self saveContext]; 



- (void)saveContext { 
    [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) { 
     if (success) { 
      DDLogInfo(@"MR_saveContext success"); 
      [self loadView]; 
      [self viewDidLoad]; 
     } else if (error) { 
      DDLogError(@"Error saving context: %@", error.description); 
     } 
    }]; 
} 
+0

那麼......問題是什麼? – yoninja

回答

1

爲什麼不直接創造出來的塊的記錄的ID?

item = [ITEM MR_createEntityInContext:defaultContext]; 
[defaultContext MR_saveToPersistentStoreAndWait]; 

// you can retrieve the id of above item here 
相關問題