我有这样的结构:
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
)