defect on getters / setters - iterating over nodes in context
johndpope opened this issue · 1 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.)
i ended up resolving this by flattening out the protobuffer.
perhaps some day - could use a protocol extension to simplify this.
https://github.com/johndpope/tensorflow/blob/256ee4fb4b95c050275acc433005bc75b7e023a7/tensorflow/swift/Sources/GenerateOps.swift