nslocalizedstring

Xcode 7 crash: [NSLocalizableString length] 30000

僤鯓⒐⒋嵵緔 提交于 2019-11-26 21:34:53
问题 The app just hangs on iOS7,8,9, makes 30000 calls to [NSLocalizableString length] The cpu is on max. see https://forums.developer.apple.com/thread/16001 also (lldb) bt * thread #1: tid = 0x2cb4df, 0x0349065c Foundation`-[NSLocalizableString length] + 6, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=2, address=0xbf728ffc) * frame #0: 0x0349065c Foundation`-[NSLocalizableString length] + 6 frame #1: 0x03490680 Foundation`-[NSLocalizableString length] + 42 frame #2:

What's NSLocalizedString equivalent in Swift?

。_饼干妹妹 提交于 2019-11-26 18:09:55
Is there an Swift equivalent of NSLocalizedString(...) ? In Objective-C , we usually use: NSString *string = NSLocalizedString(@"key", @"comment"); How can I achieve the same in Swift? I found a function: func NSLocalizedString( key: String, tableName: String? = default, bundle: NSBundle = default, value: String = default, #comment: String) -> String However, it is very long and not convenient at all. I use next solution: 1) create extension: extension String { var localized: String { return NSLocalizedString(self, tableName: nil, bundle: Bundle.main, value: "", comment: "") } } 2) in

Best practice using NSLocalizedString

你说的曾经没有我的故事 提交于 2019-11-26 08:39:43
问题 I\'m (like all others) using NSLocalizedString to localize my app. Unfortunately, there are several \"drawbacks\" (not necessarily the fault of NSLocalizedString itself), including No autocompletition for strings in Xcode. This makes working not only error-prone but also tiresome. You might end up redefining a string simply because you didn\'t know an equivalent string already existed (i.e. \"Please enter password\" vs. \"Enter password first\") Similarily to the autocompletion-issue, you

What's NSLocalizedString equivalent in Swift?

拥有回忆 提交于 2019-11-26 06:12:06
问题 Is there an Swift equivalent of NSLocalizedString(...) ? In Objective-C , we usually use: NSString *string = NSLocalizedString(@\"key\", @\"comment\"); How can I achieve the same in Swift? I found a function: func NSLocalizedString( key: String, tableName: String? = default, bundle: NSBundle = default, value: String = default, #comment: String) -> String However, it is very long and not convenient at all. 回答1: I use next solution: 1) create extension: extension String { var localized: String

How to provide a localized description with an Error type in Swift?

喜夏-厌秋 提交于 2019-11-26 03:04:46
I am defining a custom error type with Swift 3 syntax and I want to provide a user-friendly description of the error which is returned by the localizedDescription property of the Error object. How can I do it? public enum MyError: Error { case customError var localizedDescription: String { switch self { case .customError: return NSLocalizedString("A user-friendly description of the error.", comment: "My error") } } } let error: Error = MyError.customError error.localizedDescription // "The operation couldn’t be completed. (MyError error 0.)" Is there a way for the localizedDescription to

How to provide a localized description with an Error type in Swift?

我是研究僧i 提交于 2019-11-26 00:51:09
问题 I am defining a custom error type with Swift 3 syntax and I want to provide a user-friendly description of the error which is returned by the localizedDescription property of the Error object. How can I do it? public enum MyError: Error { case customError var localizedDescription: String { switch self { case .customError: return NSLocalizedString(\"A user-friendly description of the error.\", comment: \"My error\") } } } let error: Error = MyError.customError error.localizedDescription // \

How to force NSLocalizedString to use a specific language

别等时光非礼了梦想. 提交于 2019-11-25 22:56:01
问题 On iPhone NSLocalizedString returns the string in the language of the iPhone. Is it possible to force NSLocalizedString to use a specific language to have the app in a different language than the device ? 回答1: NSLocalizedString() (and variants thereof) access the "AppleLanguages" key in NSUserDefaults to determine what the user's settings for preferred languages are. This returns an array of language codes, with the first one being the one set by the user for their phone, and the subsequent