获取错误:类型’String’在Swift 4中没有成员’foregroundColor’

我是Swift的新手。 我在Swift 4中创建了一个应用程序,但是当我将SWIFT_VERSION更改为Swift 3.0时,我的代码中出现错误。

类型’String’没有成员’foregroundColor’。

如何将其转换为当前的Swift语法?

码:

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) 

在Swift 4之前,属性字符串属性不是枚举。在这种情况下,您应该使用NSForegroundColorAttributeName

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