Metaprogramming in Cocoa
summary
A code-generation tool called Sourcery parses Swift via SourceKit at build time and emits plain Swift so the compiler catches mistakes. Templates (Stencil, Swift, EJS) produce Equatable, Hashable, JSON, lens, test stubs and mocks; annotations in comments let templates skip or fine-tune fields. It integrates as a build phase, supports inline codegen for required initializers, and scales fast — New York Times repo shows one second vs two minutes for generation then full compile.
AI-written summary · about
chapters (17)
- 0:00Intro
- 0:43What is metaprogramming?
- 1:21Example of metaprogramming in Ruby
- 3:21Why would we want metaprogramming?
- 7:38Avoiding human mistakes
- 10:29Metaprogramming in Cocoa
- 11:12What is available in Swift? Swift reflection
- 13:06Will Swift add more powerful features in the future?
- 14:19Already in Swift 4
- 14:52Problems with metaprogramming
- 17:33What is Sourcery?
- 18:45Templates?
- 23:08Sourcery Features
- 24:21How to integrate Sourcery?
- 24:37Bundled templates
- 26:42Is it going to slow down my builds?
- 31:53Summary
