SWIFT – NSFONTATTRIBUTEDSTRING Work before Xcode 6.1

let timeFont = [NSFontAttributeName:UIFont(name: "Voyage", size: 20.0)]
var attrString3 = NSAttributedString("(Time)", attributes: timeFont); // <--- compiler error "Extra argument in call"

This code runs in xcode 6.0, but now I have upgraded to xcode 6.1 it no longer works, I can’t get it Be clear about what I need to make it work again. It says there is an additional argument, but this is not correct. I believe it has to do with the new available initializer, but everything I have tried does not work.

< /div>

Xcode 6.1 comes with Swift 1.1, which supports constructors that may fail. UIFont initialization may fail and return zero. When creating NSAttributedString String is also used when:

if let font = UIFont(name: "Voyage", size: 20.0) {
let timeFont = [NSFontAttributeName:font ]
var attrString3 = NSAttributedString(string: "(Time)", attributes: timeFont)
}

let timeFont = [NSFontAttributeName :UIFont(name: "Voyage", size: 20.0)]
var attrString3 = NSAttributedString("(Time)", attributes: timeFont); // <--- compiler error "Extra argument in call"

This code runs in xcode 6.0, but now I have upgraded to xcode 6.1 it doesn't work anymore, I don’t How to figure out what I need to make it work again. It says there is an additional argument, but this is not correct. I believe it has to do with the new available initializer, but everything I tried didn't work.

Xcode 6.1 comes with Swift 1.1, which supports constructors that may fail. UIFont initialization may fail and return zero. String is also used when creating NSAttributedString:

if let font = UIFont(name: "Voyage", size: 20.0) {
let timeFont = [NSFontAttributeName:font]
var attrString3 = NSAttributedString( string: "(Time)", attributes: timeFont)
}

Leave a Comment

Your email address will not be published.