Apple Tutorial Shows Value of Type 'Color' has no member' accessibleFontColor' Error

Asked 2 years ago, Updated 2 years ago, 413 views

Apple's iOS devtutorials encountered an error in lessons displaying meeting information.
Please let me know how to improve it.

Creating a CardView — iOS App Dev Tutorials | Apple Developer Documentation

error

Value of type 'Color' has no member' accessibleFontColor'

Conference information to browse

import SwiftUI

structureDailyScrum{
    variable —String
    var attendees: String
    var lengthInMinutes—Int
    var color:Color
}

extensionDailyScrum {
    static vardata: DailyScrum {
        [
            DailyScrum(title: "Design", attendees: ["Cathy", "Daisy", "Simon", "Jonathan", lengthInMinutes:10, color: Color("Design")],
            DailyScrum(title: "App Dev", attendees: ["Katie", "Gray", "Euna", "Luis", "Darla", lengthInMinutes: 5, color: Color("App Dev")),
            DailyScrum(title: "WebDev", attendees: ["Chera", "Chris", "Christina", "Eden", "Karla", "Lindsey", "Aga", "Chad", "Jenn", "Sarah", lengthInMinutes: 1, color: Color("WebDev"))
        ]
    }
}

Card UI

import SwiftUI

struct CardView:View {
    let scrum —DailyScrum
    varbody:someView {
        VStack (alignment:.leading) {
            Text(scrum.title)
                .font (.headline)
            Spacer()
            HSTack {
                Label("\(scrum.attendees.count), systemImage: "person.3")
                Spacer()
                Label("\(scrum.lengthInMinutes), systemImage: "clock")
                    .padding (.trailing, 20)
            }
            .font (.caption)
        }
        .padding()
        .foregroundColor (scrum.color.accessibleFontColor)
    }
}

structureCardView_Previews:PreviewProvider{
    static varscrum=DailyScrum.data[0]
    static var previews:someView {
        CardView (scrum:scrum)
            .background(scrum.color)
            .previewLayout (.fixed(width:400, height:60))
    }
}

swift ios xcode swiftui

2022-09-30 21:58

1 Answers

Perhaps you are creating your own project from scratch.

If you read tutorials,

accessibleFontColor is a property defined in the starting project.It returns other black or white, depending on how light or dark the scrum color is.

and

the starting project doesn't make sense if you just read here, but
At the beginning of the tutorial

Download the starter project and follow along with this tutorial, or open the finished project and expand the code on your own.

Yes

You can download the project from the Project files and the down arrow.

After downloading it, I opened it.

There are folders called Complete and StartingPoint.

The project at StartingPoint has quite a bit of code already.
There was a definition of 'accessibleFontColor' in this already written code.

So, start with the project at StartingPoint and start with it.

If there is anything else you don't understand in the middle of the tutorial, Complete seems to be the finished product, so you can compare it with this one.


2022-09-30 21:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.