(Still working with Xcode 11.0 / Swift 5.1)
((仍可使用Xcode 11.0 / Swift 5.1))
I haven't downloaded Xcode Beta 4 yet, but according to the documentation , it should be something like:
(我尚未下载Xcode Beta 4,但是根据文档 ,它应该类似于:)
ForEach(showTargets, id: .id) { item in
Text(String(item.x))
}
You can also use a struct
that conforms to Identifiable
(note that this won't work on tuple because you can't add protocol conformance):
(您还可以使用符合Identifiable
的struct
(请注意,这不适用于元组,因为您无法添加协议一致性):)
struct Targets: Identifiable {
var id: Int
var state: Bool
var x: Double
var y: Double
}
let showTargets = [
Targets(id: 1, state: false, x: 109.28, y: 109.28),
Targets(id: 2, state: false, x: 683, y: 109.28),
Targets(id: 3, state: false, x: 1256.72, y: 109.28)
]
ForEach(showTargets) { item in
Text(String(item.x))
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…