associatedType
というプロトコルを作成しました。varはassociateTypeを持つプロトコルに準拠します
public protocol HBPrerollProtocol: NSObjectProtocol {
associatedtype HBContentType
func set(content: HBContentType, startImmediately: Bool) // set configuration and begin
}
プロパティを持つビューを作成しようとしていますが、上記のプロトコルに準拠しています。
open class HBPrerollPlayerView: HBPlayerView {
open var preroll: HBPrerollProtocol?
}
ただし、プロトコルにはassociateType
があるため、これは機能しません。エラーは以下の通りだった:
Protocol 'HBPrerollProtocol' can only be used as a generic constraint because it has Self or associated type requirements
だから私はHBPrerollProtocol
を準拠し、varは、このビューであることを確認ビューを作ってみました。
class HBPrerollView<T>: UIView, HBPrerollProtocol {
typealias HBContentType = T
func set(content: HBContentType, startImmediately: Bool) { }
}
と
open class HBPrerollPlayerView<T>: HBPlayerView {
open var preroll: HBPrerollView<T>?
}
この結果異なるエラー:
Property cannot be declared open because its type uses an internal type
このクラスは分離モジュールであるため、私はタイプが一般的なので、私は違うと、このクラスを使用することができますしなければなりませんモジュール。ここ
私questingは次のとおりです。
はvarが
associatedType
を持っているプロトコルに準拠する方法はありますか?そうでない場合は、ジェネリックタイプ
T
を公開または公開するにはどうすればよいですか?