我想更改
Xcode Playground上的语言环境来测试本地化.
我找到了这个解决方案,但它不适用于Xcode 6.3.2 Playground:
http://natashatherobot.com/locale-playground-swift/
解决方法
哦,我找到了解决方案!
extension NSLocale { class func mono_currentLocale() -> NSLocale { return NSLocale(localeIdentifier: "fr") } } let original = class_getClassMethod(NSLocale.self,#selector(getter: NSLocale.currentLocale)) let swizzled = class_getClassMethod(NSLocale.self,#selector(NSLocale.mono_currentLocale)) method_exchangeImplementations(original,swizzled)
编辑:Swift 4.1版本:
extension NSLocale { @objc class func mono_currentLocale() -> NSLocale { return NSLocale(localeIdentifier: "fr") } } let original = class_getClassMethod(NSLocale.self,#selector(getter: NSLocale.current))! let swizzled = class_getClassMethod(NSLocale.self,#selector(NSLocale.mono_currentLocale))! method_exchangeImplementations(original,swizzled)