Hi, so i have this problem: I am following along a coding tutorial from a year ago. While following along i notice a couple of things do not seem to work (ViewModifier, CostumButtonStyle and most prominently the ViewBuilder wrapper), even though I have a newer version of Xcode installed on my computer. When asking Chatgpt, it says, that my version of swift is too old, which would explain a lot. When checking in the build setting it says I am using swift 5 (as well as giving me the option to downgrade to 4 and 4.2). So my question is, is chatgpt right? And if yes, how do I fix it and why doesn’t Xcode do it automatically? Thank you for your Help.
Note: When typing, Xcode still predicts and autofills the View Builder wrapper.
This it the code I had...
struct HeaderViewGeneric<Content:View>: View {
let title: String
let content: Content
init(title: String, @ViewBuilder content: () -> Content) {
self.title = title
self.content = content()
}
var body: some View {
VStack {
VStack (alignment: .leading) {
Text(title)
.font(.largeTitle)
.fontWeight(.semibold)
content
RoundedRectangle(cornerRadius: 5)
.frame(height: 2)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
Spacer()
}
}
}
This was the error:
Struct 'ViewBuilder' cannot be used as an attribute
And this was what ended up fixing it.
struct HeaderViewGeneric<Content:View>: View {
let title: String
let content: Content
init(title: String, content: @escaping () -> Content) {
self.title = title
self.content = content()
}
var body: some View {
VStack {
VStack (alignment: .leading) {
Text(title)
.font(.largeTitle)
.fontWeight(.semibold)
content
RoundedRectangle(cornerRadius: 5)
.frame(height: 2)
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
Spacer()
}
}
}