swift - 归档时如何修复“在父类中找不到'init(domain:code:userInfo :)'”?
问题描述
我正在为我现有的项目从 Swift 3 到 Swift 4.2 进行 Swift 迁移。我已经执行了 Xcode 10.1 助手,并且我的项目在调试中正确编译,但是当我尝试存档时,它给了我标题中的错误。
我的项目包括
- 主项目 -> 迁移到 Swift 4.2
- 实用程序 Pod -> Swift 3.2
在 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))
}
}
这是我存档时收到的错误。
有谁知道可能是什么问题?
谢谢
解决方案
最后,我在我的 CMError 子类中添加了 NSError init 的覆盖,并且成功存档。
public override init(domain: String, code: Int, userInfo dict: [String : Any]? = nil) {
super.init(domain: domain, code: code, userInfo: dict)
}
推荐阅读
- java - 我正在尝试使用 java 套接字使用两个不同的网络连接我的两台笔记本电脑。但它没有用
- apache-kafka - 限制 web 使用的 kafka ksqlDB 查询结果
- java - 从 IntelliJ 运行 Gradle 项目时,我可以排除构建输出吗?
- react-native - Flatlist 里面进入 Scrollview
- r - 如何在 R 中与 NA 值聚合
- arrays - 仅复制没有高级过滤器的过滤数据并将原始过滤器保留在原始表上
- encoding - 根据前缀确定 HSM_KX 标头长度
- c# - 无法定位元素——OpenQA.Selenium.NoSuchElementException
- go - Gopls 仅在我在 Macos Big Sur 中使用 sudo 执行 vim 或 vscode 时才有效
- c++ - 检查平衡括号代码的行为不符合预期