I am having problems with Swift code in a library that I have been using for some time. This seems to be due to some sort of version conflict, but I'm not sure.
Here is the code:
let attribMsg = NSAttributedString(string: msg, attributes: [NSAttributedStringKey.font:UIFont.systemFont(ofSize: 23.0)])
Here is the error message I get from the compiler:
Type 'NSAttributedStringKey' (aka 'NSString') has no member 'font' Did you mean 'zone'? Fix(button)

Using this code in another project, I noticed that on some of them I do not receive an error message, and all this compiles without any problems.
I also noticed that if I replaced the above code with the following:
let attribMsg = NSAttributedString(string: msg, attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 23.0)])
Projects with a problem will work, while others (previously working) show this other message:
'NSFontAttributeName' has been renamed to 'NSAttributedStringKey.font'

In other words, some projects work with one type of code, and some others work with another type.
Needless to say, I donβt want to change the code every time I switch from one project to another.
The experiments I did with changing the project deployment goal do not seem to matter much. So my question is: What is the way to deal with this problem?
source share