当前位置 : 主页 > 手机开发 > 其它 >

swift – NSFontAttributedString在XCode 6.1之前工作

来源:互联网 收集:自由互联 发布时间:2021-06-11
let timeFont = [NSFontAttributeName:UIFont(name: "Voyage", size: 20.0)]var attrString3 = NSAttributedString("(Time)", attributes : timeFont); // --- compiler error "Extra argument in call" 这段代码在xcode 6.0中运行,但是现在我已经
let timeFont = [NSFontAttributeName:UIFont(name: "Voyage", size: 20.0)]
var attrString3 = NSAttributedString("(Time)", attributes : timeFont); // <--- compiler error "Extra argument in call"

这段代码在xcode 6.0中运行,但是现在我已经升级到xcode 6.1它不再起作用了,我无法弄清楚我需要什么让它恢复工作.它说有一个额外的论点,但这不正确.我相信它与新的可用初始化器有关,但我尝试过的所有东西都不起作用.

Xcode 6.1附带Swift 1.1,支持可能失败的构造函数. UIFont初始化可能会失败并返回零.在创建NSAttributedString时也使用string:

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