pbm pbm - 2 months ago 16
Objective-C Question

NS_ENUM to Swift 3 not working as expected

I'm using Swift 3 and xcode 8. I'm very new to objective-C and fairly new to swift, so maybe this is an idiot question. But here goes!

I'm bridging from objective-C to swift 3. Here's a code snippet of the objective-C:

typedef NS_ENUM(NSInteger, MaplyMapType) {
MaplyMapType3D,
MaplyMapTypeFlat,
};

@interface MaplyViewController : MaplyBaseViewController

/// @brief Initialize as a flat or 3D map.
- (nonnull instancetype)initWithMapType:(MaplyMapType)mapType;


In my Swift 3 source file I instantiate a MaplyViewController. The following is the WORKING code (it compiles and runs, and no xcode errors).

theViewC = MaplyViewController(mapType: .typeFlat)


Why does this work? From references https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html and other references I think the correct code should be:

theViewC = MaplyViewController(mapType: .flat)


But that won't compile.

Answer

Likely it is, because the other identifier (MaplyMapType3D) would be 3Dinstead of type3D, but identifiers must not start with a digit. So one has to keep type.