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]
The projects are probably in different versions of Swift.
In Swift 4, NSFontAttributeName has been replaced with NSAttributedStringKey.font.
as stated here NSFontAttributeName vs NSAttributedStringKey.font
Need to confirm whether it will work on versions less than ios11
You are trying to use an iOS 11 API on a pre-iOS 11 version (likely iOS 10). Surprised that you found a tutorial already using beta features!
In the meantime, try this.
let attrs = [NSForegroundColorAttributeName: color, NSFontAttributeName: font]
and that should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With