user7582407
user7582407

Reputation:

Getting an error: Type 'String' has no member 'foregroundColor' in Swift 4

I am new to Swift. I created an app in Swift 4, but when I change the SWIFT_VERSION to Swift 3.0, I get an error in my code.

Type 'String' has no member 'foregroundColor'.

How can I convert this to current Swift syntax?

Code:

    if let p = placeholder {

      let place = NSAttributedString(string: p, attributes: //error -->[.foregroundColor: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)])


        attributedPlaceholder = place

        textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)

Upvotes: 4

Views: 3114

Answers (1)

glyvox
glyvox

Reputation: 58129

Attributed string attributes are not enums before Swift 4. You should use NSForegroundColorAttributeName in this case.

NSAttributedString(string: p, attributes: [NSForegroundColorAttributeName: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)])

Upvotes: 8

Related Questions