- Hands-On Design Patterns with Swift
- Florent Vilmart Giordano Scalzo Sergio De Simone
- 78字
- 2021-07-02 14:45:15
Renaming classes
The first step would be to rename the classes and enums so they don't expose this ugly FV prefix:
typedef NS_ENUM(NSInteger, FVMeasureUnit) {
/* ... */
} NS_SWIFT_NAME(MeasureUnit); // notice the attribute is 'after'
// And for interfaces the attribute is before
NS_SWIFT_NAME(Measure)
@interface FVMeasure : NSObject
We can now rewrite our Swift to the following:
let measure = Measure(amount: 10, unit: MeasureUnit.cups)
The class and enum names are quite better but we can go further.