[英]Swift 3.1 Nested Generics Bug with Cyclic Metadata
首先,感謝您的光臨。 我正在玩Swift 3.1嵌套泛型,我在初始化時遇到了錯誤。
class NestedProduct<T> {
enum Gadget {
case smartphone
case laptop
case fridge
case others(T)
}
enum Company {
case Samsung
case Apple
case Sony
case others(T)
}
let company: Company
let gadget: Gadget
let reviews: [T]
init(enterCompany: Company, enterGadget: Gadget, enterReView: [T]) {
company = enterCompany
gadget = enterGadget
reviews = enterReView
}
}
現在,我嘗試初始化
let product = NestedProduct<String>(enterCompany: NestedProduct.Company.Apple,
enterGadget: NestedProduct.Gadget.laptop,
enterReView: ["Good"])
但是,我收到一條錯誤消息,
GenericCache(0x11102a518):檢測到循環元數據依賴性,中止
我不知道為什么會這樣。 你能幫忙嗎? 謝謝!
看起來這是一個已知問題: https : //bugs.swift.org/browse/SR-3779
但是,我能夠通過將枚舉標記為間接來避免這種情況。 這會將相關值存儲在另一個破壞循環依賴關系的地方。
indirect enum Gadget {
case smartphone
case laptop
case fridge
case others(T)
}
indirect enum Company {
case Samsung
case Apple
case Sony
case others(T)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.