首页 > 解决方案 > 归档时如何修复“在父类中找不到'init(domain:code:userInfo :)'”?

问题描述

我正在为我现有的项目从 Swift 3 到 Swift 4.2 进行 Swift 迁移。我已经执行了 Xcode 10.1 助手,并且我的项目在调试中正确编译,但是当我尝试存档时,它给了我标题中的错误。

我的项目包括

在 Utilities Pod 中有一个 NSError 子类 (CMError)

public class CMError: NSError {

    // MARK: - Initializers

    public convenience init(type: CMErrorType) {
        self.init(domain: CMErrorDomain,
                  code: type.rawValue,
                  userInfo: type.localizedUserInfo())
    }

    public convenience init(type: CMErrorType, code: String) {
        self.init(domain: CMErrorDomain,
                  code: type.rawValue,
                  userInfo: type.localizedUserInfo(code: code))
    }

    public convenience init(type: CMErrorType, code: String, localizedDescription: String) {
        self.init(domain: CMErrorDomain,
                  code: type.rawValue,
                  userInfo: type.localizedUserInfo(code: code,
                                                   localizedDescription: localizedDescription))
    }
}

这是我存档时收到的错误。

在此处输入图像描述

在此处输入图像描述

有谁知道可能是什么问题?

谢谢

标签: swiftswift4

解决方案


最后,我在我的 CMError 子类中添加了 NSError init 的覆盖,并且成功存档。

public override init(domain: String, code: Int, userInfo dict: [String : Any]? = nil) {
    super.init(domain: domain, code: code, userInfo: dict)
}

推荐阅读