What are Lenses? Great explanation by @mbrandonw
Files:
input.swift
- sample structs for which we want helpers to be generatedlens.stencil
- sourcery template to generate lenses helpersoutput.swift
- sample lenses helpers generatedzLens.swift
- simple implementation of lenses, so you can play with it
Hints:
- Usually you want to generate helpers only for certain structs in your project. To limit scope of sourcery changes, keep your relevant structs under one directory and just point sourcery to that directory instead of whole project.
You can also use phantom protocol or annotations to mark structs you want to generate lenses for, e.g.
Then you can tweak this template to just do: