0
這是可能在過濾器中使用聚合函數:核心數據使用聚合函數在過濾器
var expressionDescriptions = [AnyObject]()
let request = NSFetchRequest(entityName: "Item")
let expressionDescription = NSExpressionDescription()
expressionDescription.name = "requestsCount"
expressionDescription.expression = NSExpression(format: "@sum.requests.id")
expressionDescription.expressionResultType = .Integer32AttributeType
expressionDescriptions.append(expressionDescription)
request.predicate = NSPredicate(format: "requestsCount != sitesCount")
request.propertiesToFetch = expressionDescriptions
do {
let items = try self.managedObjectContext.executeFetchRequest(request)
} catch {
}
此代碼返回我的錯誤:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath requestsCount not found in entity