2016-09-14 1 views
0

:스위프트 2.3 NSFetchRequest

"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 
} 

수 나는에 countForFetchRequest 더 이상 기능 때문에 빠른 2.3 엔티티 수를 얻는 방법 중 하나 조언 방법은이 나를 위해 일이다 스위프트 SWIFT 2.2

+0

사실 'countForFetchRequest'에 대해서는 2.2와 2.3 사이에서 변경되었습니다. 이에 따라 http://stackoverflow.com/questions/34652618/countforfetchrequest-in-swift-2-0을 업데이트했습니다. –

답변

0

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 
}