Search code examples
swiftnsattributedstring

NSAttributedString with Attributes in Swift 2.1


Recently, I have updated to Xcode 7.0 and the following code which was working fine in Swift 1.2 is giving me error in Swift 2.0

let messageString = inString
let attributes = [UIFont(): UIFont.systemFontOfSize(15.0)]
let attrString:NSAttributedString? = NSAttributedString(string: messageString, attributes: attributes)

Can anyone know why?


Solution

  • Define your attributes this way:

        let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(15.0)]