Slide 1

Slide 1 text

ίʔυੜ੒ͷεεϝ iPhone Dev Sapporoษڧձ Jul, 2018

Slide 2

Slide 2 text

Takeshi Ihara • Twitter: @nonchalant0303 • GitHub: Nonchalant iPhone Dev Sapporoษڧձ Jul, 2018

Slide 3

Slide 3 text

ίʔυੜ੒ • SwiftͰ͸Runtime Reflection͕͋·ΓڠྗͰ͸ͳ͍ • ϓϩάϥϜͷ࣮ߦաఔͰϓϩάϥϜࣗ਎ͷߏ଄ΛಡΈऔͬ ͨΓॻ͖׵͑ͨΓ͢Δٕज़ • ͦͷ୅ΘΓSwiftͰ͸ίʔυੜ੒Ͱղܾ͢Δ͜ͱ͕૿͖͑ͯͨ • ex. ϘΠϥʔϓϨʔτͷࣗಈੜ੒ iPhone Dev Sapporoษڧձ Jul, 2018

Slide 4

Slide 4 text

DIKit https://github.com/ishkawa/DIKit DIKit provides interfaces to express dependency graph. A code generator named dikitgen finds implementations of the interfaces, and generate codes which satisfies dependency graph. iPhone Dev Sapporoษڧձ Jul, 2018

Slide 5

Slide 5 text

Cuckoo https://github.com/Brightify/Cuckoo Cuckoo has two parts. One is the runtime and the other one is an OS X command-line tool simply called CuckooGenerator. Unfortunately Swift does not have a proper reflection, so we decided to use a compile-time generator to go through files you specify and generate supporting structs/classes that will be used by the runtime in your test target. iPhone Dev Sapporoษڧձ Jul, 2018

Slide 6

Slide 6 text

DIKit https://github.com/ishkawa/DIKit iPhone Dev Sapporoษڧձ Jul, 2018

Slide 7

Slide 7 text

Cuckoo https://github.com/Brightify/Cuckoo iPhone Dev Sapporoษڧձ Jul, 2018

Slide 8

Slide 8 text

Sourcery https://github.com/krzysztofzablocki/Sourcery Sourcery is a code generator for Swift language, built on top of Apple's own SourceKit. It extends the language abstractions to allow you to generate boilerplate code automatically. iPhone Dev Sapporoษڧձ Jul, 2018

Slide 9

Slide 9 text

Sourcery protocol Animal { func bark() } struct Dog: Animal {} // ίϯύΠϧΤϥʔ struct Apple {} iPhone Dev Sapporoษڧձ Jul, 2018

Slide 10

Slide 10 text

Stencil ϑΝΠϧςϯϓϨʔτݴޠ {% for struct in types.structs where struct.implementing.Animal %} extension {{ struct.name }} { func bark() { print("{{ struct.name }}") } } {% endfor %} ↓ Sourcery extension Cat { func bark() { print("Cat") } } iPhone Dev Sapporoษڧձ Jul, 2018

Slide 11

Slide 11 text

SourceKitten https://github.com/jpsim/SourceKitten • An adorable little framework and command line tool for interacting with SourceKit • DIKit, Cuckoo, SourceryͰ࠾༻͞Ε͍ͯΔ iPhone Dev Sapporoษڧձ Jul, 2018

Slide 12

Slide 12 text

SourceKitten ࢖ͬͯΈΔ // Source.swift struct Dog {} // SourceKitten import SourceKittenFramework let file = File(path: "./Source.swift")! let dic = try! Structure(file: file).dictionary print(dic) iPhone Dev Sapporoษڧձ Jul, 2018

Slide 13

Slide 13 text

SourceKitten [String: SourceKitRepresentable] struct Dog {} [ "key.diagnostic_stage": "source.diagnostic.stage.swift.parse", "key.substructure": [ [ "key.bodylength": 0, "key.nameoffset": 7, "key.accessibility": "source.lang.swift.accessibility.internal", "key.length": 13, "key.name": "Dog", "key.kind": "source.lang.swift.decl.struct", "key.namelength": 3, "key.offset": 0, "key.bodyoffset": 12 ] ], "key.offset": 0, "key.length": 13 ] iPhone Dev Sapporoษڧձ Jul, 2018

Slide 14

Slide 14 text

FactoryProvider https://github.com/Nonchalant/FactoryProvider • SourceKitten + StencilΛ࢖ͬͯϑΝΫτϦʔΛࣗಈੜ੒͢Δ ϥΠϒϥϦΛ࡞ͬͯΈͨʂ • ৄࡉ͸Ͳ͔͜ʹࢿྉ͋͛·͢ʂ (iOSDCམͪͯ͠·ͬͨ...) iPhone Dev Sapporoษڧձ Jul, 2018

Slide 15

Slide 15 text

Demo iPhone Dev Sapporoษڧձ Jul, 2018

Slide 16

Slide 16 text

·ͱΊ • ίʔυੜ੒ָ͍͠ʂ͕΍Γ͗͢ΔͱଐਓԽ͢ΔͷͰγϯϓϧ ʹѻ͏ͷ͕େࣄͳؾ͕ͨ͠ • iOSDC or DevSapͰ·ͨձ͍·͠ΐ͏ʂ iPhone Dev Sapporoษڧձ Jul, 2018