December 2018
Intermediate to advanced
414 pages
10h 19m
English
Let's create an AutoCopy.stencil protocol, so that Article copy implementation can be generated using Sourcery:
{% for type in types.implementing.AutoCopy %}extension {{ type.name }}: NSCopying { func copy(with zone: NSZone? = nil) -> Any { return {{type.name}}( {% map type.variables into vars using var %} {{ var.name }}: {{ var.name }}{% endmap %} {{ vars|join:"," }}) }}{% endfor %}
It will generate the following AutoCopy.generated.swift:
extension Article: NSCopying { func copy(with zone: NSZone? = nil) -> Any { return Article( id: id, title: title, contents: contents, author: author, date: date, views: views) }}
Read now
Unlock full access