Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on localizedStringWithFormat

I'm trying to localize my app, but the app crashes when it encounters my localized strings, that use localizedStringWithFormat. Here's an example:

cell.productRangeLabel.text = String.localizedStringWithFormat(NSLocalizedString("Questions %s", comment: "Subtitle showing the number of questions on each pack"), product.info!.range)

In the debugger (LLDB), product.info!.range prints the correct string, and if I print the NSLocalizedString only, it outputs the correct translation ("Preguntas %s), but in combination with localizedStringWithFormat it gives me an error:

Execution was interrupted, reason: EXC_BAD_ACCESS (code=EXC_I386_GPFLT). The process has been returned to the state before expression evaluation.

Before localizing, that string worked fine ("Questions \(product.info!.range)").

I don't know if this matters, but importing the xliff file was a nightmare. Xcode kept crashing, and I'm sure there are missing strings, but it eventually did create the Localizable.strings file.

Update: I was using the iPhone 6s (9.3) simulator when it crashed. Now I tried with the iPhone 4s (9.3), and it doesn't crash, but all strings that are variables are garbled, like: "Preguntas ☨^^" instead of "Preguntas 1-50"

like image 878
coopersita Avatar asked May 31 '26 11:05

coopersita


1 Answers

Figured it out. I had to change all %s and %d to %@.

like image 152
coopersita Avatar answered Jun 03 '26 05:06

coopersita



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!