我创建了可编码struct Person。我试图将这种结构的对象数组添加到模具的上下文中(请参见代码)。但这不起作用。
如何正确处理?
struct Person: Codable {
public var name: String
public var age: UInt8
public var description: String
public var photoURL: String
init(name: String, age: UInt8, description: String, photoURL: String) {
self.name = name
self.age = age
self.description = description
self.photoURL = photoURL
}
public static let allPersons = [
Person(name: "Name 1", age: 18, description: "Cool man", photoURL: "https://photo.ur/1"),
Person(name: "Name 2", age: 21, description: "Designer", photoURL: "https://photo.url/2")
]
}
struct MainData: Encodable {
var products: [String]
var persons: [Person]
}
try response.render("home.stencil", with: MainData(
products: [ "Music", "Fashion", "etc" ],
persons: Person.allPersons // static array with persons
))
[错误] [RouterMiddlewareWalker.swift:72 next()]无法ToRenderContext(上下文:)
P.S。解决。我在模板模板中出现语法错误。