3 ms·
Swift enums are effectively discrimated unions, which are really, really different from C (and thus, Obj-C) enums. For example, in Swift, you can have an enum
by mercutio2 8y ago
Swift enums are effectively discrimated unions, which are really, really different from C (and thus, Obj-C) enums.
For example, in Swift, you can have an enum which says its values holds exactly one of:
A) several specific semantically meaningful strings
B) some other object
C) several objects
In Obj-c, you would probably express this as a single object, and write a bunch of error prone logic to handle which of these states you’re in, possibly missing an important last minute addition in one of your methods for walking over all the possible state.
- mpweiher 8y agoThanks! In any OO language, I’d write different classes for cases A B and C that share a common message protocol (wether formal or informal) and use them uniformly/polymorphically.