I'm trying to find the best solution for a recurrent problem I have, which I solved differently each time.
Imagine I have a form in several steps ( let say 2 to begin )
My code structure is :
class SuperStepViewController: UIViewController {
//Some generic Stuff
func continueAction(sender : AnyObject?) {
//NOTHING
}
}
class Step1ViewController: SuperStepViewController {
override func continueAction(sender : AnyObject?) {
//DO SOME USEFULL STUFF
}
}
class Step2ViewController: SuperStepViewController {
override func continueAction(sender : AnyObject?) {
//DO SOME USEFULL STUFF
}
}
What I want is to change this code, to not implement the continueAction
function in the SuperViewController
, because it has no default implementation.
At a first look, I thought protocol
was a good idea. If I put continueAction
in a required protocol, I will have a compilation-time error, which is what I want.
protocol StepProtocol {
func continueAction()
}
class SuperStepViewController: UIViewController {
//GENERIC
}
class Step1ViewController: SuperStepViewController, StepProtocol {
func continueAction(sender : AnyObject?) {
//DO SOME USEFULL STUFF
}
}
class Step2ViewController: SuperStepViewController, StepProtocol {
func continueAction(sender : AnyObject?) {
//DO SOME USEFULL STUFF
}
}
But it is not enough, I want generate this compilation as soon as I subclass the superview controller. I know Java as something like Abstract class.
class Step3ViewController: SuperStepViewController {
//NO continueAction implementation => No compilation error
}
Did anyone have an idea ?
No. This is not possible in Swift. Swift does not support such activity.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.