close
1.可以return擁有associatedtype的"實際"型別
(假如有這些protocol及extension)
(實際使用)
但還是得先列出實際型別,無法用來轉型 (cell as? Viewer)
2.可以用來做比較( "==" ),
(比較cell1 及 cell2)
(因為Compiler知道他的實際型別 (有多個return只能return相同的實際型別))
3.不需曝露出實際型別,
呼叫端可认不用改Code,只要實作端內部修改return type即可
(getCell() 由Cell1 改成 Cell2,testGetCell內不需做改動)
參考資料:
https://stackoverflow.com/questions/56433665/what-is-the-some-keyword-in-swiftui/56433885#56433885
https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md
https://docs.swift.org/swift-book/LanguageGuide/OpaqueTypes.html
全站熱搜
留言列表