具有“ ANY ... IN”子句的核心数据获取谓词不起作用

时间:2019-03-27 20:57:13

标签: ios swift core-data nsfetchedresultscontroller

我有这样的结构:

Library 
----------
id: String
name: String
bookIds: NSArray?

我想获取所有我要找的书籍的图书馆。我知道这很正常。 这就是我要做的(并希望能工作):

    let bookIds: [String] = ...
    let fetchRequest: NSFetchRequest<Library> = Library.fetchRequest()
    fetchRequest.predicate = NSPredicate(format: "ANY bookIds IN %@", bookIds)

我也尝试过其他方法,例如:

    let predicates = bookIds.map {
            NSPredicate(format: "ANY %K LIKE %@", #keyPath(Library.bookIds), $0)
        }
    let predicate = NSCompoundPredicate(orPredicateWithSubpredicates: predicates)

这是我使用此fetchRequest的方式:

    librariesFetchController = NSFetchedResultsController(
            fetchRequest: fetchRequest,
            managedObjectContext: context,
            sectionNameKeyPath: nil,
            cacheName: nil
        )

0 个答案:

没有答案