Hi,
I am new to SwiftUI and am wanting to iterate over a class and present in a view the keyname and keyvalue. I understand from googling that I need to use something like the reflections API to achieve this but am struggling to convert the swift example to work with swiftui.
My current non-working code:
import SwiftUI
struct ShowClassData: View {
@ObservedObject var myClass : MyClass
var body: some View {
VStack{
var mirror = Mirror(reflecting: myClass)
mirror.children.forEach({
Text("\(child.label): \(child.value)")
})
}
}
}
Get this error:
- Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols
I've also tried the following with no luck:
for case let (label?, value) in mirror.children {
print (label, value)
}
Different error:
- Closure containing control flow statement cannot be used with function builder 'ViewBuilder'