未保存的托管对象上下文在包含 NONE 或 ANY 的谓词上产生异常
我想执行获取请求:
NSFetchRequest *fetchRequest = [NSFetchRequest new];
[fetchRequest setIncludesPendingChanges:YES];
NSSet *set = [NSSet setWithObjects:@"TESTNAME",@"TEST", nil];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"NONE name IN %@", set]];
在未保存的 NSManagedObjectContext 上执行请求时,应用程序因异常而终止:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“ALL 或 ANY 运算符的左侧必须是 NSArray 或 NSSet。”
如果我在执行之前保存上下文,那么一切都会按预期进行。关于其原因有什么想法吗?
注意:导入捆绑数据后,应用程序启动时会发生这种情况。
I'd like to execute a fetch request:
NSFetchRequest *fetchRequest = [NSFetchRequest new];
[fetchRequest setIncludesPendingChanges:YES];
NSSet *set = [NSSet setWithObjects:@"TESTNAME",@"TEST", nil];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"NONE name IN %@", set]];
when executing the request on an unsaved NSManagedObjectContext the app is terminated with exception:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The left hand side for an ALL or ANY operator must be either an NSArray or an NSSet.'
If I save the context just before execution all works as expected. Any ideas on the reason for this?
Note: This happens on application launch when bundled data is imported.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题。
我有一个由子谓词(内部有 ANY)组成的大谓词,在删除“ANY”子谓词后,我没有遇到任何崩溃。
如果您通过 UIManagedDocument 使用自动保存,如何保存上下文?
---- 已编辑 ----
只需放置 try/catch 并重新初始化谓词即可解决该问题:
似乎数据库内部存在问题,如果更改后未保存上下文,则该问题的工作方式会有所不同。
可能我做错了什么(通过解决方法修复它),但这种方法修复了我的崩溃。希望它能帮助其他人。
I'm having the same issue.
I have big predicate consisting from sub-predicates (with ANY inside), and after removing "ANY" subpredicate I do not get any crashes.
And how to save context if you are using autosave via UIManagedDocument ?
---- Edited ----
The issue was resolved simply by putting try/catch and reinitializing the predicate:
Seems like there an issue inside database which is working differently if context isn't saved after changes.
Probably I'm doing something wrong (fixing it by workaround) but this approach fixed my crash. Hopefully it will help others.