In a view I have a switch statement, where each case is a view, along these lines:
Color.clear
.overlay {
switch x {
case let .text(text):
vis.textToImage()
.resizable().scaledToFill().tag(vis)
case .image:
vis.imageAsImageView()
.resizable().scaledToFill().tag(vis)
default:
Image(systemName: "x.circle")
.resizable().scaledToFill().tag(vis)
}
}
So I want to move the “.resizable().scaledToFill().tag(vis)” to the switch statement, like this:
Color.clear
.overlay {
switch x {
case .text:
vis.textToImage()
case .image:
vis.imageAsImageView()
default:
Image(systemName: "x.circle")
}
.resizable().scaledToFill().tag(vis)
}
But then I get a compiler error: Type '() -> ()' cannot conform to 'ShapeStyle'
.
What is it that I’m doing wrong? Doesn’t the switch statement “return” whatever the “case” is? I appears to be that simple in the first code example (which is working)?