Slide 1

Slide 1 text

Don't worry, Be Lazy And let your Mac write your code for you FrenchKit 2017
 O. Halligon

Slide 2

Slide 2 text

@aligatr UIFont(name: "Avenir-It ", size: 42) 2 let format = NSLocalizedString("home.greeting ", …) String(format: format, 1 , "FrenchKit") Thread 1: EXC_BAD_ACCESS (code=1, address=0x1) "home.greetings" = "… %@ … %d …"

Slide 3

Slide 3 text

@aligatr 3

Slide 4

Slide 4 text

@aligatr label.text = L10n.homeGreetings("FrenchKit", 1, "Paris") label.font = FontFamily.Avenir.blackOblique.font(size: 18) 4

Slide 5

Slide 5 text

@aligatr Strong Typing !

Slide 6

Slide 6 text

@aligatr 6

Slide 7

Slide 7 text

@aligatr Code Generate All the Things! 7 $ swiftgen

Slide 8

Slide 8 text

No more manual maintenance! No more stringWithFormat! No more typos! Auto-completion! Type-safety!

Slide 9

Slide 9 text

@aligatr

Slide 10

Slide 10 text

@aligatr extension Phone: Equatable { static func ==(lhs: Phone, rhs: Phone) -> Bool guard lhs.model == rhs.model else { return false } guard lhs.name == rhs.name else { return false } guard lhs.priceUSD == rhs.priceUSD else { return false } // Oh joy, 30 more to go ] } 10 struct Phone { let model: PhoneModel let name: String let priceUSD: Double // and 30 other properties } But…

Slide 11

Slide 11 text

@aligatr

Slide 12

Slide 12 text

@aligatr extension PhoneModel { static let allValues: [ .iPhone, .iPhone3G, .iPhone3GS, .iPhone4, .iPhone4s, .iPhone5, .iPhone5c, .iPhone5s, .iPhoneSE, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus ] } 12 enum PhoneModel { case iPhone, iPhone3G, iPhone3GS case iPhone4, iPhone4s case iPhone5, iPhone5c, iPhone5s case iPhoneSE case iPhone6, iPhone6Plus case iPhone6s, iPhone6sPlus case iPhone7, iPhone7Plus }

Slide 13

Slide 13 text

@aligatr extension PhoneModel { static let allValues: [ .iPhone, .iPhone3G, .iPhone3GS, .iPhone4, .iPhone4s, .iPhone5, .iPhone5c, .iPhone5s, .iPhoneSE, .iPhone6, .iPhone6Plus, .iPhone6s, .iPhone6sPlus, .iPhone7, .iPhone7Plus ] } 13 enum PhoneModel { case iPhone, iPhone3G, iPhone3GS case iPhone4, iPhone4s case iPhone5, iPhone5c, iPhone5s case iPhoneSE case iPhone6, iPhone6Plus case iPhone6s, iPhone6sPlus case iPhone7, iPhone7Plus case iPhone8, iPhone8Plus, iPhoneX }

Slide 14

Slide 14 text

@aligatr

Slide 15

Slide 15 text

@aligatr 15 AutoCases.stencil AutoEquatable.stencil AutoHashable.stencil AutoLenses.stencil AutoTypeErased.stencil AutoProtocolInterface.stencil AutoClonable.stencil … Your Code Boring Code Generated for you $ sourcery

Slide 16

Slide 16 text

@aligatr sources: - CodeGenDemo/Sources templates: - CodeGenDemo/CodeGen/Templates output: CodeGenDemo/CodeGen/Generated .sourcery.yml + =

Slide 17

Slide 17 text

@aligatr

Slide 18

Slide 18 text

@aligatr extension PhoneModel { let allValues: [ .iPhone, .iPhone3G, … /* All the cases autogenerated */ … /* no more maintenance */ ] } 18 {% for enum in types.implementing.AutoCases|enum %} extension {{ enum.name }} { static let allValues: [{{ enum.name }}] = [ {% for case in enum.cases %} .{{ case.name }}, {% endfor %} ] } {% endfor %} $ sourcery enum PhoneModel: AutoCases { … }

Slide 19

Slide 19 text

@aligatr

Slide 20

Slide 20 text

@aligatr 20 $ gyro GSON ObjectMapper Decodable • • • • • •

Slide 21

Slide 21 text

@aligatr Model Generation Type Erasure Hashable Equatable Lenses Decorator Dependency Injection AutoCompletion Localizable String Constants Typed String Formats Fonts Constants Images Constants Storyboards Constants Colors Constants Type Safety Automatic Maintenance Protocol API Mocks More time for NetFlix Typos detected at compile time All Cases for Enums Reduce Hair Pulling Customizable Code JSON Parsing code Time for Wine & Chill More time to read my blog

Slide 22

Slide 22 text

@aligatr

Slide 23

Slide 23 text

@aligatr Hello, I’m Olivier github.com/SwiftGen/SwiftGen github.com/krzysztofzablocki/Sourcery github.com/AliSoftware alisoftware.github.io @aligatr 23 github.com/NijiDigital/gyro Classroom: Mastering Code Generation
 with SwiftGen & Sourcery templates