【问题标题】:coredata fetch records where the relation is not existingcoredata 获取关系不存在的记录
【发布时间】:2018-02-21 20:29:44
【问题描述】:

我有一个与另一个实体有可选关系的实体。现在我想选择那些与其他实体没有关系的记录。

我尝试使用谓词(格式:“relation = %@”,nill),但这不起作用。

如何在没有填充关系的情况下获取记录?

【问题讨论】:

标签: swift core-data


【解决方案1】:

试试这个:

let fetchRequest: NSFetchRequest = YourEntity.fetchRequest()
let predicate = NSPredicate(format: "%K == nil", #keyPath(YourEntity.yourOptionalAttribute))
fetchRequest.predicate = predicate
// the rest of your code to perform the fetch goes here

@K 用于keyPath。你只想搜索keyPath在哪里nil

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多