0
所以我有这样的代码:斯威夫特阵列扩展与结构和通用对象
struct Asset<T>: AssetProtocol{
typealias AssetType = T
var parent: T!
var children: [T]!
init(parent: T, children: [T] = [T](),){
self.parent = parent
self.children = children
}
}
protocol AssetProtocol{
associatedtype AssetProtocolType
var parent: AssetProtocolType! { get }
var children: [AssetProtocolType]! { get }
}
extension Array where Element: AssetProtocol{
fun getExtractParents() -> [<I’m not sure what type should be here the “T” doesn’t work>] {
// iterate here to get all the parents then return it.
}
}
有没有办法,我可以创造一个阵列扩展和里面的方法返回所有“父”是数组的方式?请注意,“父”的类型是通用的,如结构资产中所示。