Setting Swift names from Objective-C

Clang also provides macros that help to rename Objective-C classes and methods for Swift: NS_SWIFT_NAME

Let's start with an example that could arise if you're writing a cooking application or any other app that requires measuring. When cooking, you'll often be hit with multiple volumes, units, and so on. It is possible to abstract it with a Measure class:

// A measuring unit
typedef
NS_ENUM(NSInteger, FVMeasureUnit) {
FVLiters,
FVMilliliters,
FVCups
};

// The Measure class,
@interface FVMeasure : NSObject

@property (nonatomic, readonly) double amount;
@property (nonatomic, readonly) FVMeasureUnit unit;

+ (instancetype) measureWithAmount:(double) amount unit:(FVMeasureUnit) unit;
+ (instancetype) withCups:(double) value;

- (double) valueInUnit:(FVMeasureUnit) unit;
/* more convenience initializers */
@end

While the previous code is not explicitly bad, it is not very Swift-y:

let measure = FVMeasure(amount: 10, unit: FVMeasureUnit.cups)
let inMilliliters = measure.value(in: .milliliters)