After upgrading to Xcode 6.1 Beta 2 from Xcode 6 Beta 7, the following no longer works:
let font = UIFont(name: "Arial", size: 16)
let colour = UIColor.redColor()
let attributes = [NSFontAttributeName: font, NSForegroundColorAttributeName: colour]
I have tried specifically declaring the dictionary as
let attributes: [NSString : AnyObject] = [NSFontAttributeName: font, NSForegroundColorAttributeName: colour]
but I am receiving the error "Cannot convert ... 'Dictionary' to 'NSString!'". Declaring the key as NSString!
rather than NSString
complains that NSString!
is not hashable. Any clues?
Sorted. As usual, the actual error is a red herring. UIFont(name: , size:)
now has an init?
initialiser, and so is optional. Correct usage is now :
let font = UIFont(name: "Arial", size: 16)! // Unwrapped
let colour = UIColor.redColor()
let attributes: [NSString : AnyObject] = [NSFontAttributeName: font, NSForegroundColorAttributeName: colour]
or, more correctly:
if let font = UIFont(name: "Arial", size: 16) {
let colour = UIColor.redColor()
let attributes: [NSString : AnyObject] = [NSFontAttributeName: font, NSForegroundColorAttributeName: colour]
// ...
}
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