Is is also possible to apply the NS_SWIFT_NAME macro to enum cases as well as class and instance methods:
// A measuring unit
typedef NS_ENUM(NSInteger, FVMeasureUnit) {
FVLiters NS_SWIFT_NAME(l),
FVMilliliters NS_SWIFT_NAME(ml),
FVCups,
} NS_SWIFT_NAME(MeasureUnit);
Let's also rename one of the static initializers and the conversion method's name to something shorter:
+ (instancetype) withCups:(double) value NS_SWIFT_NAME(init(cups:));
- (double) valueInUnit:(FVMeasureUnit) unit NS_SWIFT_NAME(in(unit:));
Notice how you declare an initializer with the init(cups:) syntax; this follows the same conventions as when you specify selectors in Swift.
Now it is possible to use the shorthand enum value when referencing the unit:
let tenCups = Measure(cups: 10)
let tenCupsInLiters = tenCups.in(unit: .l)
In this section, we've covered how to adapt your legacy Objective-C code naming style to the modern Swift feel. We're almost done with interoperability, and still have to cover a great feature added to the Objective-C language: lightweight generics.