Last active
August 12, 2024 07:03
-
-
Save enomoto/2c8892a30472997f4ada7458ee8236f8 to your computer and use it in GitHub Desktop.
Change locale in XCTestCase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private extension MyTests { | |
private func setLocaleAsJP() { | |
let original = class_getClassMethod(NSLocale.self, #selector(getter: NSLocale.current))! | |
let swizzled = class_getClassMethod(NSLocale.self, #selector(NSLocale.myCurrentLocale))! | |
method_exchangeImplementations(original, swizzled) | |
} | |
} | |
// https://stackoverflow.com/questions/31065859/how-can-i-change-the-locale-on-the-xcode-playground | |
fileprivate extension NSLocale { | |
@objc class func myCurrentLocale() -> NSLocale { | |
return NSLocale(localeIdentifier: "ja") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment