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?
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.”
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With