gpt4 book ai didi

ios - 在 CoreData NSSet 上使用 'filteredSetUsingPredicate' 时崩溃(NSInvalidArgumentException : set argument is not an NSSet)

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:32:44 28 4
gpt4 key购买 nike

假设我有 NSManagedObject Zoo,他得到了一个到名为 cats 的“Cat”的连接 oneToMany,这个连接是 NSSet。当我使用函数 'filteredSetUsingPredicate ',我遇到了以下代码的崩溃:

Zoo *zoo = //intance of our zoo with all the animals - from core data 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"catSize == Big"];
NSArray *arrayOfCats = [zoo.cats filteredSetUsingPredicate:predicate];

崩溃堆栈如下:

Terminating app due to an uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableSet unionSet:]: set argument is not an NSSet'

Crashed: com.apple.main-thread
1 CoreFoundation 0x180f51798 -[NSMutableSet unionSet:] + 96
2 CoreData 0x182f24154 -[_NSFaultingMutableSet willReadWithContents:] + 716
3 CoreData 0x182f05f10 -[_NSFaultingMutableSet count] + 28
4 Foundation 0x181a93828 -[NSSet(NSPredicateSupport) filteredSetUsingPredicate:] + 68

这只会偶尔发生一次,并且可能与我在后台上下文中所做的更新和删除有关(如果我坚持这个例子,则添加或删除猫)。知道如何保护我的应用程序不崩溃吗?对属性猫的任何访问都会导致崩溃。

最佳答案

您应该查看关系删除规则以确保其设置正确

关于ios - 在 CoreData NSSet 上使用 'filteredSetUsingPredicate' 时崩溃(NSInvalidArgumentException : set argument is not an NSSet),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38683718/

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