Invincible_Pain
Invincible_Pain

Reputation: 571

SwiftUI is complaining Type of expression is ambiguous without more context in navigationBarItems leading

I'm just placing some views in navigationBarItems, leading property. but Xcode keep complaining "Type of expression is ambiguous without more context" in my first Text element:

var body: some View {
    NavigationView {
        List {
            ForEach(people) {person in
                PersonView(person: person)
            }
        }.navigationBarItems(leading: VStack {
                HStack(spacing: 100) {
                    Text("Find People").font(.system(size: 30)).bold()
                    Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
                }
                HStack(spacing: 100) {
                     Text("Import from: ")
                     ForEach(socialIcons, id: \.self) {icon in
                         Image(icon).resizable().frame(width: 25, height: 25)
                     }
                }
            },
            trailing: nil
        )
    }
}

This is what I wanna achieve enter image description here

This is my snapshot of the code: enter image description here

Upvotes: 2

Views: 1292

Answers (1)

Mojtaba Hosseini
Mojtaba Hosseini

Reputation: 119380

Don't Trust Xcode:

Xcode is not very intelligent to tell you what is the real issue in SwiftUI enough (yet). So believing or not, the issue is with the trailing: nil.

You should get rid of it!

So it would be:

    .navigationBarItems(leading: VStack {
        HStack(spacing: 100) {
            Text("Find People").font(.system(size: 30)).bold()
            Text("Follow All").foregroundColor(Color(ColorUtils.hexStringToUIColor(hex: Constants.THEME.THEME_COLOR)))
        }
        HStack(spacing: 100) {
            Text("Import from: ")
            ForEach(socialIcons, id: \.self) {icon in
                Image(icon).resizable().frame(width: 25, height: 25)
            }
        }
    }) /* `trailing: nil` removed */

Upvotes: 3

Related Questions