iOS Swift 3架构问题

问题描述 投票:0回答:1

我正在努力找到解决我遇到的经常性问题的最佳解决方案,每次都解决不同的问题。

想象一下,我有几个步骤的表格(比如2开始)

我的代码结构是:

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
    }

}

我想要的是改变这段代码,不在continueAction中实现SuperViewController函数,因为它没有默认实现。

初看起来,我认为protocol是个好主意。如果我把continueAction放在一个必需的协议中,我将有一个编译时错误,这就是我想要的。

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
    }

}

但这还不够,我想在我对superview控制器进行子类化时立即生成这个编译。我知道Java就像抽象类一样。

class Step3ViewController: SuperStepViewController { 

   //NO continueAction implementation => No compilation error

}

有人有想法吗?

ios swift architecture
1个回答
0
投票

不,这在Swift中是不可能的。 Swift不支持此类活动。

© www.soinside.com 2019 - 2024. All rights reserved.