Hello dear community!
I'm a new to SwiftUI and going through the official Develop in Swift Tutorials.
I've just finished the chapter Customize views with properties where it was show that it's possible to declare computed properties like this:
var iconName: String {
if isRainy {
return "cloud.rain.fill"
} else {
return "sun.max.fill"
}
}
And then use it as follows:
var body: some View {
VStack {
Text(day)
Image(systemName: iconName)
}
}
This is really cool and I liked it and I decided that I want to do the similar thing for the project from the previous chapter (ChatBubble), so I decided to declare the following property in my custom ChatBubble view:
struct ChatBubble: View {
let text: String
let color: Color
let isEllipsis: Bool
var shape: Shape {
if isEllipsis {
Ellipse()
} else {
RoundedRectangle(cornerRadius: 8)
}
}
var body: some View {
Text(text)
.padding()
.background(color, in: shape)
}
}
But first, I got a warning where I declare shape: Shape that it must be written any Shape like this:
var shape: any Shape { …
But in both cases I got a error in the body:
'buildExpression' is unavailable: this expression does not conform to 'View'
What does it mean? Why I can't use the computed property with shape like the computed property for String?
Thank you very much in advance.
Topic:
UI Frameworks
SubTopic:
SwiftUI