NSAttributedStringKey给出未解析的标识符错误 [英] NSAttributedStringKey giving an unresolved identifier error

查看:365
本文介绍了NSAttributedStringKey给出未解析的标识符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照在线教程来构建杂志类型的iOS应用程序。我正在尝试使用NSAttributedStringKey,但不断收到如下所示的错误。有什么想法?

I'm following an online tutorial to build a magazine type iOS application. I'm attempting to use NSAttributedStringKey but keep getting the error shown below. Any ideas?

这是导致错误的代码行:

This is the line of code that is causing the error:

let attrs = [NSAttributedStringKey.foregroundColor: color, NSAttributedStringKey.font: font] as [NSAttributedStringKey : Any]


推荐答案

这些项目可能是不同版本的Swift。

The projects are probably in different versions of Swift.

在Swift 4中,NSFontAttributeName已被NSAttributedStringKey取代.font。

In Swift 4, NSFontAttributeName has been replaced with NSAttributedStringKey.font.

如此处所述 NSFontAttributeName vs NSAttributedStringKey .font

需要确认它是否适用于低于ios11的版本

Need to confirm will it work in versions less than ios11

这篇关于NSAttributedStringKey给出未解析的标识符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆