我在使用一段时间的库中使用Swift代码时遇到了一些麻烦.它似乎与某种版本冲突有关,但我不确定.
这是代码:
let attribMsg = NSAttributedString(string: msg,
attributes: [NSAttributedStringKey.font:UIFont.systemFont(ofSize: 23.0)])
Run Code Online (Sandbox Code Playgroud)
这是我从编译器得到的错误消息:
Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font'
Did you mean 'zone'? Fix(button)
Run Code Online (Sandbox Code Playgroud)
在不同的项目中使用此代码,我注意到在其中一些我没有得到错误消息,它都编译没有任何问题.
我还注意到,如果我用以下代码替换上面的代码:
let attribMsg = NSAttributedString(string: msg,
attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 23.0)])
Run Code Online (Sandbox Code Playgroud)
有问题的项目将起作用,而其他项目(以前正在工作)显示此另一条消息:
'NSFontAttributeName' has been renamed to 'NSAttributedStringKey.font'
Run Code Online (Sandbox Code Playgroud)
换句话说,一些项目使用一种类型的代码,而另一些项目使用另一种类型.
不用说,每次从一个项目切换到另一个项目时,我都不想更改代码.
我改变项目部署目标的实验似乎并没有太大的区别.我的问题就出现了:处理这个问题的方法是什么?
我将我的代码从swift 3.3迁移到4.1而且我收到了这个错误.我怎样才能解决这个问题 ?有什么建议?
progressView.titleLabelAttributedText = NSAttributedString(string: MyxStrings.sharedInstance.SENDING, attributes: [NSFontAttributeName: Scully.sharedInstance.APP_REGULAR_FONT_SMALL!])
Run Code Online (Sandbox Code Playgroud)