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.
}
}
有沒有辦法,我可以創造一個陣列擴展和裏面的方法返回所有「父」是數組的方式?請注意,「父」的類型是通用的,如結構資產中所示。