Cannot use custom view in SwiftUI

You are missing the string: param in the initializer. Please find the updated code below:

var body: some View {
    VStack(alignment: .leading) {
        Title(string: "Welcome")
        Title(string: "to SwiftUI")
    }
}

FYI:
I have created one sample application

// MARK - CustomView

struct ContentView : View {
    var body: some View {
        VStack{
            CustomView(aString: "First String")
            CustomView(aString: "Second String")
        }
    }
}

// MARK - CustomView

struct CustomView : View {
    var aString: String
    var body: some View {
        Text(aString)
    }
}

You need to add string: to your Title() initializer:

var body: some View {
    VStack(alignment: .leading) {
        Title(string: "Welcome")
        Title(string: "to SwiftUI")
    }
}

Compiler errors are currently misleading and not located near where the real issue is.

Tags:

Swift

Swiftui