The Foundation framework takes advantage of Swift 3's new nested enumeration feature. This feature allows the migrator to import related Objective-C enumerations into Swift under a common type. For example, the NSDateFormatterStyle
and NSDateFormatterBehavior
enumerations are imported as nested enumerations to the DateFormatter
class in Swift. Let's see how we get to a nested enumeration in Swift 3, starting with an Objective-C enumeration.
In Objective-C:
typedef NS_ENUM(NSUInteger, NSDateFormatterStyle), { NSDateFormatterNoStyle = kCFDateFormatterNoStyle, NSDateFormatterShortStyle = kCFDateFormatterShortStyle, NSDateFormatterMediumStyle = kCFDateFormatterMediumStyle, NSDateFormatterLongStyle = kCFDateFormatterLongStyle, NSDateFormatterFullStyle = kCFDateFormatterFullStyle }; typedef NS_ENUM(NSUInteger, NSDateFormatterBehavior){ NSDateFormatterBehaviorDefault = 0, NSDateFormatterBehavior10_0...