2015-11-30 97 views
-2

让说,我有如下协议:数据类型

protocol DataResponse { .... }

我的问题是,我怎么能做出这样下面另一种协议? :

protocol AnotherProtocol { var data:[DataProtocol] { get } }

当我试图做上述下面我Struct,我得到Type 'MyStruct' does not conform to protocol 'AnotherProtocol'

struct myStruct : AnotherProtocol { 

    var data:[a struct implements DataProtocol] ... 
} 

回答

0

你想知道什么?

protocol DataResponse { 
} 

protocol AnotherProtocol { 
    var data:[DataResponse] { get } 
} 

struct myStruct : AnotherProtocol { 
    var data:[DataResponse] 
} 

此代码编译。

0

你在你的答案代码不是很清楚,所以我不知道你正在尝试做的,但应该为你的作品:

protocol DataProtocol { 
} 

protocol AnotherProtocol { 
    var data:[DataProtocol] { get } 
} 

struct dataStruct : DataProtocol { 
} 

struct myStruct : AnotherProtocol { 

    var data:[DataProtocol] { 
     return [dataStruct()] 
    } 
} 
+0

我想要做的就是'结构MYSTRUCT:AnotherProtocol {dataStruct] { return [dataStruct()] } } '因为我有很多结构体实现'DataProtocol' –