gpt4 book ai didi

ios - MagicalRecord - 检索最后插入的记录 ID

转载 作者:行者123 更新时间:2023-11-29 12:12:41 26 4
gpt4 key购买 nike

我正在使用 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

关于ios - MagicalRecord - 检索最后插入的记录 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32904226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com