在Swift 4中设置textView.typingAttributes前景色

Fra*_*s F 5 uitextview nsattributedstring ios swift4 xcode9-beta

我正在使用下面的方法在Swift 3中将textView.typingAttributes前景色设置为红色.

textView.typingAttributes[NSForegroundColorAttributeName] = UIColor.red
Run Code Online (Sandbox Code Playgroud)

现在,我已经向Swift 4迁移了它的显示错误,我尝试如下,但它仍然显示错误.什么是正确的设置方式?

textView.typingAttributes[NSAttributedStringKey.foregroundColor] = UIColor.red
Run Code Online (Sandbox Code Playgroud)

mat*_*att 8

试试这个:

textView.typingAttributes[NSAttributedStringKey.foregroundColor.rawValue] =
    UIColor.red
Run Code Online (Sandbox Code Playgroud)