Swift 2.0 - 无法转换MigrationCall到错误抛出函数

时间:2015-09-24 07:37:40

标签: ios swift2 xcode7

我正在从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
    }
}

0 个答案:

没有答案