I am relying heavily on String.format in combination with a Strings.xml Files to customize the user experience. This worked perfect until I recently switched from SDK 3.3 to 3.5 and iOS SDK 8.2.
Running an application in a simulator (8.1 or 8.2) from within the Titanium Studio leads to a crash without any feedback or the Strings.xml content not being applied.
Running the same application from within XCode in the same simulator version leads to the follow EXC_BAD_ACCESS in KrollContext.m. Screenshot attached.
The corresponding function call in Javascript looks like this:
filterTimeframeLabel.setText( String.format(L('Option_Filter_Timeframe_Details'), Util2.formatDate(transactionFilter.timeframe[0], 'DD.MM.YYYY'), Util2.formatDate(transactionFilter.timeframe[1], 'DD.MM.YYYY')) );
Compiling an AdHoc and running the same application on a device works perfectly. This just applies to the simulator.
In addition also simple String.Formats fail:
label.setText ( String.format('%d test', 99) );
Displays "99" in the simulator and "99 test" on the device.
HI, Please provide a simple test case to reproduce your crashes issue, That will be really helpful. Thanks On the other hand, about missing text after %dm it is a known issue, ref: TIMOB-18640 Regards, Shuo
Can confirm. Here's a simple test case: {noformat} $ mkdir /tmp/foo $ cd /tmp/foo $ ti create --name foo --id foo --workspace-dir
pwd
$ cd foo $ vi Resources/app.js {noformat} Remove all contents ofapp.js
and replace with: {noformat} String.format("%2$d %1$s", "foo", 2); {noformat} Then run it in the simulator: {noformat} $ ti build --platform iphone --target simulator --device-id FF5C5A2C-2D8C-4ED2-A95A-AFD23AEE8F15 --sim-type iphone {noformat} It will crash badly after the Appcelerator default splash screen. See, the second argument is the "d" and the first is the "s".String.format("%1$s %2$d", "foo", 2);
works fine.String.format("%2$d %1$s", "foo", 2);
fails. And it only fails in the simulator. This happens in both 3.5.1.RC and 4.0.0.RC4.I have validated the issue with our latest SDK and
String.format("%2$d %1$s", "foo", 2)
still crashes, whileString.format("%1$d %2$s", 2, "foo")
, so I am wondering why someone would specify the arguments in the reversed order. The bad access has to do with exactly that and would need to be adjusted for this special case accordingly.The issue is because the formats are structured incorrectly. When using the correct format-indexing, everything works. Besides that, the initial ticket request was already fixed before and does not occur anymore (tested on both Simulator and device).
Closing with reference to the above observations.