在Swift 4中出现错误:类型'String'没有成员'foregroundColor'

4

我是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)
1个回答

8

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

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

1
谢谢您...另外,关于这个问题:现在可以上传Swift 4应用程序到iTunes Connect吗?还是太早了? - user7582407
5
使用 Xcode 的 beta 版本无法上传应用至 App Store。 - Code Different

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接