我正在从Swift 1.0迁移到Swift 2.0。自动迁移后,我有很多警告和错误。我正在努力修复它们。这是其中一个修复但我仍然有警告。
警告"迁移。调用错误抛出函数不能 转换&#34。在行
let signedUsers = try managedObjectContext!.executeFetchRequest(fetchRequest) as! [PMMUser]
功能代码:
func signedUser() -> PMMUser? {
let fetchRequest = NSFetchRequest(entityName: "PMMUser")
let predicate = NSPredicate(format: "signed == true")
fetchRequest.predicate = predicate
do {
let signedUsers = try managedObjectContext!.executeFetchRequest(fetchRequest) as! [PMMUser]
if signedUsers.count == 0 {
throw PMMUserError.NoSignedUser
} else if signedUsers.count > 1 {
throw PMMUserError.MoreThatOneUserSigned
} else {
return signedUsers.first
}
} catch let error as NSError {
print(error)
return nil
}
}