> Say we split up Foundation's enums roughly into categories. You have your > policies (NSURLCacheStoragePolicy, NSDateFormatterStyle), states/answers > (NSURLSessionTaskState, NSQualityOfService), and, well, lists > (NSSearchPathDirectory, NSStringEncoding). Given those, I’d say protocols, > generics, and zero-cost abstractions are frequently a better choice (but not > always). For instance, IMHO a closed protocol better models commonly-used > styles. I agree a lot that enums are not nearly as useful as they seem at first sight, and I know I'm not the only one who started with an enum-based solution and realised later that it doesn't work out as expected. But I didn't encounter that with enums in Foundation — obviously, because I'm not writing Foundation code ;-), so could you give some concrete examples where the different alternatives would be a better fit? My experience is that enums loose their appeal quickly when you want to attach behaviour or properties to the different cases… but I think closed protocols would also be just a workaround, inferior compared with case classes and ad-hoc union types.
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution