defect on getters / setters - iterating over nodes in context
Closed this issue · 2 comments
I have confirmed this sample working fine.
stencil string
{% for article in operations %}
<li>{{ article.title }} by {{ article.author }}</li>
{% endfor %}
struct Article {
let name: String
let author: String
}
let articleContext = [
"articles": [
Article(name: "Migrating from OCUnit to XCTest", author: "Kyle Fuller"),
Article(name: "Memory Management with ARC", author: "Kyle Fuller"),
]
]
let environment = stencilSwiftEnvironment()
let template = StencilSwiftTemplate(templateString:stencilString,environment:environment)
let generated = try template.render(["articles": articleContext["articles"]])
For my case, I have some swift protobuffer classes that are auto generated by Apple.
here's the actual class
https://github.com/johndpope/swift-grpc-tensorflow/blob/master/Sources/op_def.pb.swift
Basically it implements SwiftProtobuf.Message
public struct Tensorflow_OpDef: SwiftProtobuf.Message (protocol only)
from what I can see - the only difference between the
struct Article
and
struct Tensorflow_OpDef
is the getters / setters
public var name: String {
get {return _storage._name}
set {_uniqueStorage()._name = newValue}
}
when I reference the internal code / then it works.
{% for op in operations %}
name:{{ op.**_storage._name** }}
{% endfor %}
Expected
{% for op in operations %}
name:{{ op.name }}
{% endfor %}
doesn't render any results.
(I get that this may not be fixable. but maybe some warnings could be added to help debug.)
This seems more like a Stencil question?
Yes. it will come to haunt users of this library down the track.
I've opened up a ticket over at stencil.