I am trying to define attibutes for Strings, with the following statement (IOS app)
var attributes = [NSAttributedString.Key: Any]()
attributes[NSAttributedString.Key.foregroundColor] = newColor
I get a compiler error :
Type 'NSAttributedString.Key' (aka 'NSString') has no member 'foregroundColor'
even though the constant is defined in doc
So I change to
attributes[NSForegroundColorAttributeName] = newColor
Get another error:
Cannot subscript a value of type '[NSAttributedString.Key : Any]' (aka 'Dictionary<NSString, Any>') with an index of type 'String'
Which is bizarre again, as when I test (option-click in attribute name) the type of NSForegroundColorAttributeName, I get
static let foregroundColor: NSAttributedString.Key
I finally change to:
attributes[NSForegroundColorAttributeName as NSAttributedString.Key] = newColor
which works.
Am I missing something or is this a bit messy ?