【问题标题】:Bad access when creating NSPredicate instance [duplicate]创建 NSPredicate 实例时访问错误[重复]
【发布时间】:2018-09-14 03:56:25
【问题描述】:

这是在 Xcode 9.2 中工作的代码:

let request: NSFetchRequest<MyModel> = MyModel.fetchRequest()
request.predicate = NSPredicate(format: "saved = %@", true as CVarArg)

更新到 Xcode 9.3 和 Swift 4.1 后,代码崩溃了:

线程 1:EXC_BAD_ACCESS(代码=1,地址=0x1)

这是崩溃的部分

NSPredicate(format: "saved = %@", true as CVarArg)

MyModel 实体的已保存属性声明为布尔值。为什么这开始发生,但它之前有效?

【问题讨论】:

标签: swift xcode core-data nspredicate swift4.1


【解决方案1】:

您不必过于复杂,如果您一直在寻找 saved = true ,那么只需在谓词中使用字符串文字即可。

NSPredicate(format: "saved == true")

【讨论】:

    猜你喜欢
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 2021-12-27
    • 2016-07-31
    • 1970-01-01
    相关资源
    最近更新 更多