Closed mbrandonw closed 6 years ago
@mbrandonw I was looking for that the whole day since read your article, but didn't realise that one could use selector for that. I'm not sure it would work though with custom property accessors and instance variables, didn't do ObjC for a while, but that should be rare anyway. Thanks for the tip, I'll make a PR. I suppose we will just return nil for now, but can consider better options later in general.
Cool, thanks for looking into it! FWIW I did that because I found it in the docs:
https://stencil.fuller.li/en/latest/templates.html#variables
[
"item": [
"name": "John"
],
"key": "name"
]
"The result of {{ item[key] }} will be the same as {{ item.name }}. It will first evaluate the result of {{ key }}, and only then evaluate the lookup expression."
Hi! I noticed that if you reference a field for a variable that doesn't exist, you get a crash with SIGABRT. For example this template render:
will crash.
To fix I believe all you have to do is guard this
value(forKey:)
call:https://github.com/stencilproject/Stencil/blob/00e71c1b4dc2ec6c0f87841a10e34299e6059fcc/Sources/Variable.swift#L107
with this:
Does the current code work as expected, or is it worth fixing?
Thanks!