I am trying to use the countForFetchRequest
method on a managed object context in Swift 2.0.
I note that the error handling for executeFetchRequest
has been changed across to the new do-try-catch
syntax:
func executeFetchRequest(_ request: NSFetchRequest) throws -> [AnyObject]
but the countForFetchRequest
method still uses the legacy error pointer:
func countForFetchRequest(_ request: NSFetchRequest,
error error: NSErrorPointer) -> Int
...and I am having a bit of trouble figuring out how to use this in Swift 2.0.
If I do the same thing as pre-Swift 2.0:
let error: NSError? = nil
let count = managedObjectContext.countForFetchRequest(fetchRequest, error: &error)
I get errors saying to remove the &
, but if I remove that I get another error saying that NSError
cannot be converted to an NSErrorPointer
.
Any help would be appreciated about how to get this working.