為什么協議中的唯一屬性要求不能被符合的屬性所滿足?為什么下面的代碼會產生錯誤?protocol ProtocolA {
var someProperty: ProtocolB { get }}protocol ProtocolB {}class ConformsToB: ProtocolB {}class SomeClass: ProtocolA {
// Type 'SomeClass' does not conform to protocol 'ProtocolA' var someProperty: ConformsToB
init(someProperty: ConformsToB) {
self.someProperty = someProperty }}這個類似問題的答案合乎道理。但是,在我的示例中,該屬性是只獲取的。為什么這不管用?這是SWIFT的一個缺點,還是有什么理由這樣做是合理的?
2 回答

一只名叫tom的貓
TA貢獻1906條經驗 獲得超3個贊
ProtocolA
associatedtype T: ProtocolB
var someProperty: T { get }
- 2 回答
- 0 關注
- 603 瀏覽
添加回答
舉報
0/150
提交
取消