升级至Swfit 3:无法覆盖已标记为不可用的'init' [英] Upgrading to Swfit 3: cannot override 'init' which has been marked unavailable
问题描述
我刚刚继承了一个包含 Apple的ResearchKit (RK)的iOS项目.
I just inherited an iOS project which incorporates Apple's ResearchKit (RK).
我已经升级到RK的最新版本,也升级到了Swift3.虽然我在iOS和RK上工作,但我仍然不太自信.无论如何,有一个叫做SurveyTask
的类,它实现了RK中的ORKOrderedTask
.
I have upgraded to the most recent version of RK and also to Swift 3. While I have worked in iOS and RK, I am still not very confident. Anyways, There is a class called SurveyTask
which implements an ORKOrderedTask
from RK.
无法覆盖已标记为不可用的"init"
cannot override 'init' which has been marked unavailable
此函数的最后,已经定义了stepz
,我们有:
at the end this function, stepz
already defined, we have:
super.init(identifier: "survey", steps: stepz)
我检查了具有init
功能的ORKOrderedTask
类定义.
I checked the ORKOrderedTask
class definition, which has an init
function.
我一直在阅读有关初始化器但没有发现任何东西.在SurveyTask
中的init
之前使用override
或convenience
不会更改任何内容.同样的错误.任何帮助将不胜感激.
I have been reading about initializers but haven't found anything. Using override
or convenience
before the init
in SurveyTask
doesn't change anything. Same error. Any help would be greatly appreciated.
XCode 8.1版.
XCode version 8.1.
推荐答案
以下是模拟无参数初始化程序并避免unavailable
错误的方法:
Here's how you can mimic a parameterless initializer and avoid the unavailable
error:
class MyClass: ParentWithUnavailableInitializer {
init(workaround _: Void = ()) {
// Call a designated initializer
super.init(param: "a very sensible value")
}
}
// At a call site
let obj = MyClass()
在Swift 3.2和Swift 4中工作.
Works in Swift 3.2 and Swift 4.
这篇关于升级至Swfit 3:无法覆盖已标记为不可用的'init'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!