Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while accessing members of UIColor extension

I want to move custom colors to an extension of UIColor:

extension UIColor {
    static var nonSelectedTabColor: UIColor {
        return UIColor(white: 0.682, alpha: 1) // #AEAEAE
    }
}

But on trying to access it, its causing me an error:

private static let defaultBorderColor = .nonSelectedTabColor

Reference to member 'nonSelectedTabColor' cannot be resolved without a contextual type.

What is the issue here? How can I fix this?

like image 918
j.krissa Avatar asked Mar 07 '23 11:03

j.krissa


1 Answers

The compiler cannot know that you are referring to a member of UIColor. Either

private static let defaultBorderColor = UIColor.nonSelectedTabColor

or

private static let defaultBorderColor: UIColor = .nonSelectedTabColor

would solve the issue. In the second line, the type UIColor is inferred from the context, and .nonSelectedTabColor is an “implicit member expression.”

like image 59
Martin R Avatar answered Mar 16 '23 09:03

Martin R