// Generated Swift Interface enumDisplayMode : Int { case mode256Colors =0 case modeThousandsOfColors =1 case modeMillionsOfColors =2 }
The DisplayMode256Color would starts with numbers if the compiler removes its prefix. So the compiler would retain the model as beginning.
We can use NS_SWIFT_NAME to modify the case’s name in Swift to avoid this trouble.
// Generated Swift Interface enumDisplayMode : Int { case with256Colors =0 case thousandsOfColors =1 case millionsOfColors =2 }
Converting factory methods in OC to convenience initialization methods in Swift
Sometimes, the factory methods we written in OC don’t conform the compiler’s conversion standard. We can convert them to initialization methods in Swift manually.
The compiler can only recognize the controllerForURLKind as a factory method. The class MyController’s suffix must equal to the factory method’s prefix.
// Use it in Swift var preferences =Sandwich.Preferences() preferences.isCrusty =true
Renaming enums to nested types
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Declare in Objective-C typedef NS_ENUM(NSInteger, SandwichBreadType) { brioche, pumpernickel, pretzel, focaccia } NS_SWIFT_NAME(SandwichPreferences.BreadType); // The class's name must be OC name.
// Generated Swift Interface extensionSandwich.Preferences { publicenumBreadType : Int { case brioche =0 case pumpernickel =1 case pretzel =2 case focaccia =3 } }
// Use it in Swift let type =Sandwich.Preferences.BreadType.focaccia
Renaming Objective-C methods
1 2 3 4 5
// Declare in Objective-C - (NSSet<NSString *> *)previousMissionsFlownByAstronaut:(SKAstronaut*)astronaut NS_SWIFT_NAME(previousMissions(flownBy:));
// Generated Swift Interface openfuncpreviousMissions(flownByastronaut: SKAstronaut) -> Set<String>