私は従来のSwift 2.2プロジェクトに取り組んでいます。よく知られたプロトコル指向のプラクティスを自分のコードに実装したいと思います。UIViewControllerの自己制約プロトコルの拡張
protocol SuccessPresenting {
func presentSucess(title: String, message: String)
}
extension SuccessPresenting where Self: UIViewController {
func presentSucess(title: String?, message: String) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
let dismissAction = UIAlertAction(title: "ОК", style: .Default, handler: nil)
alertController.addAction(dismissAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}
class NewViewController: UIViewController, SuccessPresenting {
func foo() {
presentSucess(nil, message: "Done!")
}
}
けれども、それはスウィフト3.1上の作品で、ここで私はエラーを取得する:The NewViewController doesn't conform to protocol SuccessPresenting
しかし、私はすでにプロトコル拡張を使用していることを行っているとして、なぜ私は、私のVCでのプロトコルの実装を記述する必要がありますか? 何か助けていただければ幸いです。 これはSwiftです注意してください2.2
あなたの 'NewViewController'から' SuccessPresenting'適合性制約を削除してみてください。つまり、 'class NewViewController:UIViewController {// presentSuccessを呼び出すコード}' –
@ NandiinBaoそれも私を助けなかった –