You need to take out this, because you can’t declare a variable within the body
property:
var debug: some View {
MyViewWithError(property: self.property)
}
This line will crash your app:
Image(symbols[numbers[3]])
Because numbers[3]
is 3
but symbols[3]
doesn’t exist, thus giving you a fatal index out of range error.
And you need to add a parameter here to tell SwiftUI what image you want to display:
Image()
.frame(width: 32.0, height: 32.0)
And a final note: You should enclose your code within backticks ```
on the line before and the line after the block in order to format it properly. It helps with readability and also when other posters try to copy and paste your code to test out solutions and such. For instance, this line caused errors when I pasted into Xcode:
private var symbols = [“food1”, “food2”, “food3”]
Why, because since it wasn’t included in a code block, the forum software converted the quotes into unicode “smart” or “curly” quotes, which Xcode doesn’t like. You can see the difference:
private var symbols = ["food1", "food2", "food3"]