2017-03-15 12 views
2

UIViewの変数があり、プロトコルもMTMathKeyboardです。クラスとプロトコルのスイフトタイプ

私は

var keyboard: (UIView & MTMathKeyboard) 
var keyboard: UIView<MTMathKeyboard> 

プロトコルを実装非ジェネリッククラスのインスタンスのための構文は何でしょうか、試してみましたか

+0

スウィフトではまだ簡単な解決法はないと思います。このブログの記事をチェックしてください:http://chris.eidhof.nl/post/classes-and-protocols/ – tonisuter

+0

関連(重複?)http://stackoverflow.com/questions/25623761/swift-property-with-type- and-protocol –

+0

関連項目:http://stackoverflow.com/q/42090028/2976878 – Hamish

答えて

3

は、私はあなたがこの道を行くべきだと思う:

protocol MTMathKeyboard: class { 

} 

class YourClass<MTMathKeyboard where T:UIView> { 
    var keyboard: T! 
} 
0
プレースホルダプロトコルを満たすために、プロトコル構成を使用してのUIViewを拡張することができ

protocol UIViewClass {} 
extension UIView:UIViewClass {} 


var keyboard : UIViewClass & MTMathKeyboard 
1

はスウィフト4で使用することができます:

let keyboard: UIView & MTMathKeyboard 
関連する問題