Problem description
String.format is crashing the app if the arguments are not strings
Steps to reproduce and sample code
var win = Ti.UI.createWindow({
title:'test',
backgroundColor:'white',
});
var cost = 10;
var coins = 20;
var message = String.format(L("menu_iconsbuy"),cost,coins);
// setting cost and coins as Strings, it works
// var message = String.format(L("menu_iconsbuy"),cost.toString(),coins.toString());
Ti.API.info('#### ' + message);
win.open();
strings.xml (in the i18n folder) is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- All localized strings should go here -->
<resources>
<string name="menu_iconsbuy">This icon set will cost %1$s coins.\n You have %2$s coins\nWant to buy it ?</string>
</resources>
The workaround is to convert the numeric values to string:
var message = String.format(L("menu_iconsbuy"),cost.toString(),coins.toString());
Attached the crash log.
Issue does not reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 iOS iPhone Simulator: iOS SDK version: 6.0
Issue is not reproducible, Hence closing. Verified on: Device : iPad 4, iOS version: 6 SDK: 3.1.0.v20130409124549 CLI version : 3.1.0-cr OS : MAC OSX 10.7.5 Appcelerator Studio, build: 3.1.0.201304052347 XCode : 4.5.1
Thanks. It just took me 2 hours to find that bug!
value.toString()
solved it.