Consider this case:
class A {
var someCommonProperty: Int = 0
}
class B {
var someCommonProperty: Int = 0
}
class C {
var someCommonProperty: Int = 0
}
protocol UnionABC {
var someCommonProperty: Int
}
extension A: UnionABC {}
extension B: UnionABC {}
extension C: UnionABC {}
I'm sorry, but I don't understand the point you are trying to make.
If you pass in a value of type (A | B | C) to a function, what might you want
to do with that value?
If you want to do one thing if the value is type A, something else if the value
is type B, and something else if the value is
I like the justification of unions as lightweight restricted ad-hoc enums.
Definitely agreed with you in that the compiler will have to do more work, and
should be able to handle the implicit conversion without going bonkers.
Thanks!
Austin
> On May 16, 2016, at 3:35 AM, Haravikk
Hi Austin,
let me repeat the example so that clarify my point from this example.
protocol cannot do this:
func input(value: ProtocolForABC) {
print(value.someCommonProperty)
if value is A {
} else if value is B {
} else if value is C {
} else {
Union is far better then generic enum/protocol solution.
* It can extend the original enum and make it powerful.
enum ResultDataType {
case Music
case Video
case File
}
enum FailureType {
case HTTP404
case HTTP502
}
enum FailureTypev2 {
case
FWIW, totally agree with this opinion. I also don't understand why "poor
beginner who would start typing swift code before reading the manual"
becomes so important when we decide to accept or not some new feature or
change. Are we working on language that must be used just to teach
101 - 106 of 106 matches
Mail list logo