gpt4 book ai didi

ios - 谓词不适用于 NSSet

转载 作者:行者123 更新时间:2023-11-30 13:03:38 26 4
gpt4 key购买 nike

我想过滤categoryId == value但我的谓词失败的地方。这是我的代码。
categoryList 是 VenueCategory 类的对象数组,categoryId 是 Category 类的属性。

Place

 class Place: NSManagedObject {

class func GetPlaces(keys:[String],values:[String],forPlaceTab:Bool?,visitType:VisitType) -> [Place] {

//1
let managedContext = CoreDataStack.sharedStack().mainContext

var predicates = [NSPredicate]()
//2
let fetchRequest = NSFetchRequest(entityName:TABLE_PLACE)

for (index, key) in keys.enumerate() {
let value = values[index]

let predicateFormat = key != "categoryId" ? "\(key) == \(value)" : "ANY categoryList.categoryId == \(value)"
let resultPredicate = NSPredicate(format: predicateFormat)
predicates.append(resultPredicate)



}

if let forPlaceTab = forPlaceTab{

let predicateFormat = "isPlaceTab == \(forPlaceTab.boolValue)"
let resultPredicate = NSPredicate(format: predicateFormat)
predicates.append(resultPredicate)
}

fetchRequest.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: predicates)

//3
//var error: NSError?
do {

if let results = try managedContext.executeFetchRequest(fetchRequest) as? [Place]{
return results
}

} catch let error as NSError {
print(error)
}

return []
}
}

最佳答案

我遇到了问题。问题是类别未添加到类别列表中。谓词没问题。

关于ios - 谓词不适用于 NSSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39636667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com