由于从2.2迁移到2.3,我现在得到了以下错误:
以下代码中的“调用中的额外参数”:
class func objectCountForEntity (entityName:String, context:NSManagedObjectContext) -> Int {
let request = NSFetchRequest(entityName: entityName)
var error:NSError?
let count = context.countForFetchRequest(request, error: &error)
if let _error = error {
print("\(#function) Error: \(_error.localizedDescription)")
} else {
print("There are \(count) \(entityName) object(s) in \(context)")
}
return count
}有谁能建议我如何获得一个实体,因为countForFetchRequest不再像它在Swid2.2中那样起作用
发布于 2017-08-04 19:01:32
Swift 3.1
这是我的工作。
class func objectCountForEntity (entityName:String, context:NSManagedObjectContext) -> Int {
let request = NSFetchRequest(entityName: entityName)
var error:NSError?
let count = try! context.count(for: request)
if let _error = error {
print("\(#function) Error: \(_error.localizedDescription)")
} else {
print("There are \(count) \(entityName) object(s) in \(context)")
}
return count
}https://stackoverflow.com/questions/39493404
复制相似问题