我希望能够使用IN子句搜索实体的关系.
我有以下设置:
我有以下设置:
我想发送一系列昵称,找到与这些昵称相关的所有人.
//array of names to find let nameArray: [String] = ["Tom","Tommy","Thomas"] // find all Persons who have a nickname associated with that person let predicate = NSPredicate(format: "ANY Person.nickName in %@",nameArray) var fetch = NSFetchRequest(entityName: "Person") fetch.predicate = predicate var fetchError : NSError? = nil // executes fetch let results = context?.executeFetchRequest(fetch,error: &fetchError)
‘NSInvalidArgumentException’,原因:’谓词的未实现的sql生成:(任何Person.nickName IN {“Tom”,“Tommy”,“Thomas”})’
解决方法
您应该在NSPredicate中使用关系名称.
试试这个:
试试这个:
let predicate = NSPredicate(format: "ANY personToNick.nickName in %@",nameArray)