至于性能原因,我已将此全局变量用于我的日期格式。更新到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中使用线程化日期格式化程序的方法。有什么想法吗?