2 ms·
> Swift enums concisely solve lots of problems that are easy-but-annoying in Objective-C. Curious as to what those might be, can you shed some light? I was al
by mpweiher 8y ago
> Swift enums concisely solve lots of problems that are easy-but-annoying in Objective-C.
Curious as to what those might be, can you shed some light?
I was also puzzled by the emphasis on enums in Swift, as they are a language feature I rarely if ever use in Objective-C, not because I want to and they are inadequate, but because I generally don't see much of a need for them.
- mercutio2 8y agoSwift 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.