![](/img/trans.png)
[英]Can I make a Swift enum generic, so I can use its cases to infer a type for a generic class?
[英]How to make generic protocol not generic in Swift? So I can use it as parameter type
protocol A : AnyObject {
associatedtype T
}
protocol B : A where T == Int {
}
func a(b: B) {
}
我試過這個。 但是我再次收到此錯誤: Error:(19, 11) protocol 'B' can only be used as a generic constraint because it has Self or associated type requirements
不確定a(b:)
函數中的內容,但您也可以將其設為通用。
func a<T: B>(b: T) {
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.