gpt4 book ai didi

ios - 在应用程序关闭后使用不保存的 MagicalRecord 截断所有内容

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:42:31 25 4
gpt4 key购买 nike

我正在使用 Magical Record,我想做的是当用户进入一个多项目选择器 TableView 时,他可以选中和取消选中许多项目,当按下完成时,这些项目将被保存。

当我使用该应用程序时没有问题,但是当我离开和返回时,所有之前检查过的项目和新项目都会被检查(假设我在启动时检查了 5 个项目,然后我去返回多项目选择器,取消选中它们并选中其他 5 个,当我离开应用程序后返回多项目选择器时将选中 10 个)。

这是我按下选择器的“完成”按钮时的代码:

 -(void)selector:(KNMultiItemSelector *)selector didFinishSelectionWithItems:(NSArray *)selectedItems
{

[self dismissViewControllerAnimated:YES completion:^{
currentFriends = selectedItems;


[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {

[FriendsSelected MR_truncateAll];

for (KNSelectorItem * user in selectedItems) {

FriendsSelected *friend = [FriendsSelected MR_createEntityInContext:localContext];
friend.friendID = user.selectValue;
friend.friendName = user.displayValue;
NSLog(@"Friend %@ Saved", friend.friendName);

}

}];

}];

}

我尝试在应用程序终止时保存,我尝试使用完成和后台任务,没有任何接缝可以工作。也许我遗漏了什么?

PS:我试过this other answer但它不起作用,并且 MR_save 在我使用的版本中已被弃用。

最佳答案

使用 MR_truncateAllInContext: 确保使用上下文删除数据,该上下文用于您使用 saveWithBlock: 启动的实际保存操作

关于ios - 在应用程序关闭后使用不保存的 MagicalRecord 截断所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25400036/

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