NSFontAttributedString 在 XCode 6.1 之前工作 [英] NSFontAttributedString worked before XCode 6.1

查看:16
本文介绍了NSFontAttributedString 在 XCode 6.1 之前工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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,它不再起作用,我不知道需要什么才能让它恢复工作.它说有一个额外的论点,但这是不正确的.我相信它与新的可失败初始化器有关,但我尝试过的所有方法都不起作用.

This code worked in xcode 6.0, but now that I've upgraded to xcode 6.1 it doesn't work anymore and I can't figure out what I need to get it back working. It says that there is an extra argument, but that's not correct. I believe that it has something to do with the new failable initializers, but everything that I've tried doesn't' work.

推荐答案

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

Xcode 6.1 comes with Swift 1.1 that supports constructors that can fail. UIFont initialisation can fail and return nil. Also use string: when creating NSAttributedString:

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

这篇关于NSFontAttributedString 在 XCode 6.1 之前工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆