UIView
の変数があり、プロトコルもMTMathKeyboard
です。クラスとプロトコルのスイフトタイプ
私は
var keyboard: (UIView & MTMathKeyboard)
var keyboard: UIView<MTMathKeyboard>
プロトコルを実装非ジェネリッククラスのインスタンスのための構文は何でしょうか、試してみましたか
UIView
の変数があり、プロトコルもMTMathKeyboard
です。クラスとプロトコルのスイフトタイプ
私は
var keyboard: (UIView & MTMathKeyboard)
var keyboard: UIView<MTMathKeyboard>
プロトコルを実装非ジェネリッククラスのインスタンスのための構文は何でしょうか、試してみましたか
は、私はあなたがこの道を行くべきだと思う:
protocol MTMathKeyboard: class {
}
class YourClass<MTMathKeyboard where T:UIView> {
var keyboard: T!
}
:
protocol UIViewClass {}
extension UIView:UIViewClass {}
var keyboard : UIViewClass & MTMathKeyboard
はスウィフト4で使用することができます:
let keyboard: UIView & MTMathKeyboard
スウィフトではまだ簡単な解決法はないと思います。このブログの記事をチェックしてください:http://chris.eidhof.nl/post/classes-and-protocols/ – tonisuter
関連(重複?)http://stackoverflow.com/questions/25623761/swift-property-with-type- and-protocol –
関連項目:http://stackoverflow.com/q/42090028/2976878 – Hamish