Swift 1.2中的线程dateformatter

时间:2015-02-12 12:19:17

标签: swift nsdateformatter nsthread

至于性能原因,我已将此全局变量用于我的日期格式。更新到Swift 1.2后,这个不再工作,并且在合并swiftmodule时给了我一个分段错误11。

let kCachedDateFormatterKey:String = "kCachedDateFormatterKey"
var dateFormatter:NSDateFormatter {
    get {
        var threadDictionary = NSThread.currentThread().threadDictionary
        var dateFormatter:NSDateFormatter? = threadDictionary.objectForKey(kCachedDateFormatterKey) as? NSDateFormatter

        if dateFormatter == nil {
            dateFormatter = NSDateFormatter()
            var nlLocale:NSLocale = NSLocale(localeIdentifier: "nl_NL")
            dateFormatter?.locale = nlLocale
            dateFormatter?.timeZone = NSTimeZone(name: "UTC")
            threadDictionary.setObject(dateFormatter!, forKey: kCachedDateFormatterKey)
        }
        return dateFormatter!
    }
}

我正在寻找一种在Swift 1.2中使用线程化日期格式化程序的方法。有什么想法吗?

0 个答案:

没有答案