1
我有一個類型,我試圖具體擴展:AnyObserver<[MyModel]>
。這將是易於擴展,如果我不是在一個數組傳遞作爲Element
,我可以做這樣的事情:如何擴展接受數組通用元素的類型?
extension AnyObserver where Element: MyModel {...}
然而,實際上Element
是一個數組,所以我試圖做類似任一所示:
extension AnyObserver where Element: Array<MyModel> {...}
extension AnyObserver where Element: Array<T: MyModel> {...}
extension AnyObserver where Element == Array<MyModel> {...}
extension AnyObserver where Element == [MyModel] {...}
這些結果編譯錯誤,如:
Same-type requirement makes generic parameter non-generic
Type 'Element' constrained to non-protocol type
什麼是正確的方式爲這個CA創建擴展SE?