Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computed properties on objects appear to not be supported #219

Closed
NocturnalSolutions opened this issue Jun 7, 2018 · 1 comment · Fixed by #246
Closed

Computed properties on objects appear to not be supported #219

NocturnalSolutions opened this issue Jun 7, 2018 · 1 comment · Fixed by #246
Labels
swift bug Something we can't do because of Swift/Apple doesn't support this yet.
Milestone

Comments

@NocturnalSolutions
Copy link

If an object or struct is passed to a template, you can generally access the properties on the object/struct by using {{ objectName.propertyName }}. However, this appears not to work with computed properties.

In other words, with a class like:

class foo {
  var bar: String = {
    return "baz"
  }
}

If you instantiate a foo, put it in the context dictionary, and then try to print {{ foo.bar }} in the template, nothing prints.

In my actual code, I didn't want my bar value to be an actual normal property calculated when init-ing the struct, so I ended up working around it by implementing bar as a Stencil filter.

@ilyapuchka
Copy link
Collaborator

Swift Mirror does not support computed properties, it is used to lookup properties of swift types. If you use NSObject-based types KVO will be used. There is no workaround for that, as far as I know. You could though define an extension on your type that creates a context dictionary that you use in Stencil instead of accessing properties, but that's far from a good solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
swift bug Something we can't do because of Swift/Apple doesn't support this yet.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants