Cannot infer contextual base in reference to member 'trailingIcon'

I am a beginner and i am working on the Scrumdinger tutorial . this message keeps popping up "Cannot infer contextual base in reference to member 'trailingIcon'" I do not know how to fix it. Here is my code import SwiftUI

struct CardView: View {   let scrum: DailyScrum   var body: some View {     VStack(alignment: .leading){       Text(scrum.title)         .font(.headline)         .accessibilityAddTraits(.isHeader)               Spacer()       HStack {         Label("(scrum.attendees.count)", systemImage: "person.3")           .accessibilityLabel("(scrum.attendees.count) attendees")         Spacer()         Label("(scrum.lengthInMinutes)", systemImage: "clock")           .accessibilityLabel("(scrum.lengthInMinutes) minute meeting")           .labelStyle(.trailingIcon)       }       .font(.caption)     }     .padding()     .foregroundColor(scrum.theme.accentColor)   } }

struct CardView_Previews: PreviewProvider {   static var scrum = DailyScrum.sampleData[0]   static var previews: some View {     CardView(scrum: scrum)       .background(scrum.theme.mainColor)       .previewLayout(.fixed(width: 400, height: 60))   } } Any ideas?

When you paste code, please use code formatter:

import SwiftUI

struct CardView: View {
    let scrum: DailyScrum
    
    var body: some View {
        VStack(alignment: .leading){
            Text(scrum.title)
                .font(.headline)
                .accessibilityAddTraits(.isHeader)
            
            Spacer()
            
            HStack {
                Label("(scrum.attendees.count)", systemImage: "person.3")
                    .accessibilityLabel("(scrum.attendees.count) attendees")
                Spacer()
                Label("(scrum.lengthInMinutes)", systemImage: "clock")
                    .accessibilityLabel("(scrum.lengthInMinutes) minute meeting")
                    .labelStyle(.trailingIcon)
            }
            .font(.caption)
        }
        .padding()
        .foregroundColor(scrum.theme.accentColor)
    }
}

Are you sure to have defined the extension to LabelStyle ?

import SwiftUI

struct TrailingIconLabelStyle: LabelStyle {
    func makeBody(configuration: Configuration) -> some View {
        HStack {
            configuration.title
            configuration.icon
        }
    }
}

extension LabelStyle where Self == TrailingIconLabelStyle {
    static var trailingIcon: Self { Self() }
}

struct TrailingIconLabelStyle: LabelStyle {
  func makeBody(configuration: Configuration) -> some View {
    HStack {
      configuration.title
      configuration.icon
    }
  }
}

extension LabelStyle where Self == TrailingIconLabelStyle {
  static var trailingIcon: Self { Self() }
}

This is the code

Maybe it has something to do with me using Xcode 12.5 instead of 13

`I am also doing the DetailVew And i am getting an error message stating that "compiling failed Cannot find type 'DetailView_Previews' in scope Here is my code for that. I am not using the starting project files. I am wondering if that is the problem? ``


struct DetailView: View {
    let scrum: DailyScrum

    var body: some View {
        Text("Hello, World!")
    }
}

struct DetailView_Previews: PreviewProvider {
    static var previews: some View {
        DetailView(scrum: DailyScrum.sampleData[0])
    }
}

I have met the same problem in this chapter, my Xcode version is 12.5.1. Have you find solutions?

Cannot infer contextual base in reference to member 'trailingIcon'
 
 
Q