Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading to Swfit 3: cannot override 'init' which has been marked unavailable

I just inherited an iOS project which incorporates Apple's ResearchKit (RK).

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.

enter image description here

cannot override 'init' which has been marked unavailable

at the end this function, stepz already defined, we have:

super.init(identifier: "survey", steps: stepz)

I checked the ORKOrderedTask class definition, which has an init function.

enter image description here

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 version 8.1.

like image 317
jeffery_the_wind Avatar asked Nov 10 '16 11:11

jeffery_the_wind


1 Answers

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()

Works in Swift 3.2 and Swift 4.

like image 126
deej Avatar answered Oct 19 '22 01:10

deej