Skip to content

Instantly share code, notes, and snippets.

@FilipZawada
FilipZawada / description.md
Last active February 27, 2020 00:06
Generating Lenses helpers using Sourcery

What are Lenses? Great explanation by @mbrandonw

Files:

  • input.swift - sample structs for which we want helpers to be generated
  • lens.stencil - sourcery template to generate lenses helpers
  • output.swift - sample lenses helpers generated
  • zLens.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.