0
Swift enumの1つのケースと、プロトコルに基づいた関連する値を一致させたいと思います。具体的には、関連する値の実際の型に大文字小文字を限定したいのですが、それが可能なのかどうかは分かりません。Swiftの実際のタイプでスイッチケースを制限する方法
protocol MyProtocol {}
extension Int:MyProtocol {}
extension Double:MyProtocol {}
enum MyEnum {
case something(MyProtocol)
case nothing
}
let somethingInt = .something(10)
let somethingDouble = .something(10.0)
switch somethingInt {
case .something(let aValueInt):
!!! I want to figure out how to limit this case to a double or an int
case .something(let aValueDouble):
!!! I want to figure out how to limit this case to a double or an int
case .nothing:
break
}