日記
今日スーパーに行ったら枝付きの枝豆を売っていたのでさっき茹でた.うまかったが,冷凍のほうが単価安いんだろうなと思うと悲しくなったしその価値観にも悲しくなった.
今日書いたコード
import Foundation protocol Hoge { associatedtype FirstConstrationType associatedtype SecondConstrationType func plint() } extension Hoge where FirstConstrationType == String { func plint() { print("only first") } } extension Hoge where FirstConstrationType == String, SecondConstrationType == String { func plint() { print("first and second") } } struct Impl: Hoge { typealias FirstConstrationType = String typealias SecondConstrationType = String } Impl().plint() // first and second
初めて知ったこと
これ
If a conforming type satisfies the requirements for multiple constrained extensions that provide implementations for the same method or property, Swift uses the implementation corresponding to the most specialized constraints.