MagicalRecord - 检索最后插入的记录 ID
MagicalRecord - Retrieve the last inserted record id
我正在使用 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);
}
}];
}
为什么不直接创建它呢?
item = [ITEM MR_createEntityInContext:defaultContext];
[defaultContext MR_saveToPersistentStoreAndWait];
// you can retrieve the id of above item here
我正在使用 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);
}
}];
}
为什么不直接创建它呢?
item = [ITEM MR_createEntityInContext:defaultContext];
[defaultContext MR_saveToPersistentStoreAndWait];
// you can retrieve the id of above item here