Ios swift协议中的数据类型
假设我有以下协议:Ios swift协议中的数据类型,ios,swift,protocols,Ios,Swift,Protocols,假设我有以下协议: 协议数据响应{….} 我的问题是,如何制定另一个协议,如以下所示: 协议另一个协议{var data:[DataProtocol]{get} 当我试图在下面的结构中执行上述操作时,我得到类型“MyStruct”不符合协议“AnotherProtocol” struct myStruct : AnotherProtocol { var data:[a struct implements DataProtocol] ... } 你想实现什么 protocol DataRe
协议数据响应{….}
我的问题是,如何制定另一个协议,如以下所示:
协议另一个协议{var data:[DataProtocol]{get}
当我试图在下面的结构中执行上述操作时,我得到类型“MyStruct”不符合协议“AnotherProtocol”
struct myStruct : AnotherProtocol {
var data:[a struct implements DataProtocol] ...
}
你想实现什么
protocol DataResponse {
}
protocol AnotherProtocol {
var data:[DataResponse] { get }
}
struct myStruct : AnotherProtocol {
var data:[DataResponse]
}
这段代码可以编译。您的答案中的代码不是很清楚,所以我不知道您想做什么,但这应该对您有用:
protocol DataProtocol {
}
protocol AnotherProtocol {
var data:[DataProtocol] { get }
}
struct dataStruct : DataProtocol {
}
struct myStruct : AnotherProtocol {
var data:[DataProtocol] {
return [dataStruct()]
}
}
我想做的是struct myStruct:AnotherProtocol{var data:[dataStruct]{return[dataStruct()]}
,因为我有很多结构实现DataProtocol