Reputation: 223
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?
Upvotes: 4
Views: 4300
Reputation: 539685
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.”
Upvotes: 6