Share
Embed
Transcript
16 slides
-
Takeshi Ihara • Twitter: @nonchalant0303 • GitHub: Nonchalant iPhone Dev
Sapporoษڧձ Jul, 2018 -
ίʔυੜ • SwiftͰRuntime Reflection͕͋·ΓڠྗͰͳ͍ • ϓϩάϥϜͷ࣮ߦաఔͰϓϩάϥϜࣗͷߏΛಡΈऔͬ ͨΓॻ͖͑ͨΓ͢Δٕज़ • ͦͷΘΓSwiftͰίʔυੜͰղܾ͢Δ͜ͱ͕૿͖͑ͯͨ •
ex. ϘΠϥʔϓϨʔτͷࣗಈੜ iPhone Dev Sapporoษڧձ Jul, 2018 -
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 -
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 -
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 -
Sourcery protocol Animal { func bark() } struct Dog: Animal
{} // ίϯύΠϧΤϥʔ struct Apple {} iPhone Dev Sapporoษڧձ Jul, 2018 -
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 -
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 -
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 -
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