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

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

The type 'String' does not have a member 'foregroundColor'.

How can I convert this to the current Swift syntax?

the 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)
+4
source share
1 answer

String attribute attributes are not listed before Swift 4. In this case, you should use NSForegroundColorAttributeName.

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

Source: https://habr.com/ru/post/1682686/


All Articles