Error in countForFetchRequest in swift 2.3 migration

时间:2016-11-09 08:18:22

标签: ios core-data swift2

I migrated my code to swift 2.3 which resulted in "Extra argument 'error' in call" for the line:

var count:Int = moc.countForFetchRequest(fetchRequest, error: nil)

So, I found to handle it with try catch from: Swift: Extra argument 'error' in call, and put it inside try catch as follows:

var count:Int = 0

do {
    count = try moc.countForFetchRequest(fetchRequest)
    return count
} catch let error as NSError {
    print("Error: \(error.localizedDescription)")
    return count
}

Now its showing error on returning count. Error is: "Cannot convert return expression of type 'int' to return type 'NSArray' ". Couldn't figure out the new syntax error. Please help.

0 个答案:

没有答案