0

this is a follow up question to this : Assign ViewController to Class or vice versa

So i have a ViewController called SwipeStepViewController, it subclasses from ORKActiveStepViewController. In the SwipeStep class i try to override the default ViewController with my custom SwipeStepViewController.

I tried to override the +stepViewControllerClass method and return my Custom Viewcontroller inside the SwipeStep class: import ResearchKit

class SwipeStep:ORKActiveStep{

    override func stepViewControllerClass(){
        return SwipeStepViewController.self
    }

}

but this does not work at all. I use researchkit, but i guess it is a general swift question.

Community
  • 1
  • 1
plasmid0h
  • 186
  • 2
  • 13

3 Answers3

1

I don't have any experience with ResearchKit, but after taking a look at the Objective-C code I believe your method should be:

override class func stepViewControllerClass() -> AnyClass {
    return SwipeStepViewController.self
}

To explain why you're getting the errors:

Method does not override any method from its superclass.

and

'SwipeStepViewController.Type' is not convertible to '()'

take a look at the class method (indicated by the +) you're supposedly overriding:

+ (Class)stepViewControllerClass {
    return [ORKFormStepViewController class];
}

Compare this with your method:

override func stepViewControllerClass(){
    return SwipeStepViewController.self
}

which is neither a class method, nor returns a class and it's clear where the errors are coming from.

Community
  • 1
  • 1
ABakerSmith
  • 22,759
  • 9
  • 68
  • 78
  • Just a small note : i had to remove the "class" keyword in the first codeblock. I guess, because it's a protocol ? – plasmid0h Jun 29 '15 at 19:22
1

Quite late to the party, but I believe your function should be as follows:

class SwipeStep : ORKActiveStep {
    static func stepViewControllerClass() -> SwipeStepViewController.Type {
        return SwipeStepViewController.self
    }
}
tensormit
  • 79
  • 4
0

That function should return a Class. Take a look at the section in the Swift reference on Metatype Types:

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html

Your function should be

override func stepViewControllerClass(){
    return SwipeStepViewController.self
}
brucehappy
  • 9
  • 1
  • 1