gpt4 book ai didi

swift 2.3 NSFetchRequest

转载 作者:行者123 更新时间:2023-11-28 16:11:31 25 4
gpt4 key购买 nike

自从从 2.2 迁移到 2.3 后,我现在收到以下错误:

"Extra Argument in call" in the following code:

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
}

谁能告诉我如何在 swift 2.3 中获取实体计数,因为 countForFetchRequest 不再像在 swift 2.2 中那样运行

最佳答案

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
}

关于 swift 2.3 NSFetchRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39493404/

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