可转换的CoreData NSPredicate导致EXC_BAD_ACCESS

时间:2017-12-13 12:49:52

标签: ios swift core-data nspredicate transformable

使用Transformable在核心数据的NSPredicate中搜索数组元素是否存在的正确方法是什么?

我有一个Entity,其AttributeType Transformable Custom Class [Int]的{​​{1}}设置为EXC_BAD_ACCESSenter image description here 我用它来存储,以及Ints阵列。它适用于存储,但在尝试使用NSPredicate

获取它时,我得到//day is an Int (1) in this case NSPredicate(format: "%d IN operationalDays",day) NSPredicate(format: "%i IN operationalDays",day) NSPredicate(format: "%@ IN operationalDays",day) NSPredicate(format: "operationalDays CONTAINS %d",day) NSPredicate(format: "operationalDays CONTAINS %i",day) NSPredicate(format: "operationalDays CONTAINS %@",day)

我知道

  

operationalDays是{1,2,3,4}

我正在尝试,但他们都失败了,错误。

QColor

当我在崩溃后检查谓词时,我得到了

  

谓词:(1 IN OPERDays);

  

谓词:(operationsDays CONTAINS 1)

2 个答案:

答案 0 :(得分:3)

可转换属性作为二进制数据存储在Sqlite DB中。除非谓词也包含二进制数据,否则无法对该数据运行查询。可转换属性遵循NSCoding协议,因此,Core Data知道如何序列化和反序列化属性。

P.S。要查看Sqlite抛出的错误,请尝试添加

-com.apple.CoreData.SQLDebug 1

到Xcode方案中的“启动时传递的参数”。

enter image description here

答案 1 :(得分:-1)

你应该使用这种风格的谓词

let predicate = NSPredicate(format: "%@ IN days", argumentArray: [valueOfArgumentHere])