Appcelerator Titanium Useful Marcos and alias

Appcelerator Titanium SDK is purely JavaScript platform. So, Web developers can also create native application for top SmartPhone OS Android and iOS, HTML5 (Mobile Web). Now Titanium beta released for Blackberry also. I hope soon I can see my favorite OS Windows Phone in that list.

Appcelerator Titanium
Appcelerator Titanium

Appcelerator team created few marcos for us, to minimize keystrokes. Here is the list of Marcos :-

1) Ti is alias for Titanium

For example :- We can use"prints info message"); instead of"prints info message");

2) L is for get locale string

For example :- We can use L("welcome"); instead of Ti.Locale.getString("welcome");

This above method is using for localization string. It will automatically brings the give key name value for strings.xml for the language folder (en|es|ja…) in side i18n folder.

Remember one thing it is also best to pass default value to this getString method. So, if there is no key match it will return this default value. This is how we have to do Ti.Locale.getString("welcome","Hello ");

3) alert is alias of Titanium.UI.createAlertDialog for single message.

AlertDialog is used for show dialog box with multiple buttons (for E.g. Ok Cancel or Yes, No, Cancel).

alert is also default method of Javascript. alert("This default alert"); This will show dialog box with only Ok button.

var dialog = Ti.UI.createAlertDialog({ cancel: 1, buttonNames: ['Confirm', 'Cancel', 'Help'], message: 'Would you like to delete the file?', title: 'Delete' }).show();

dialog.addEventListener(‘click’, function(e) {
//Clicked cancel, first check is for iphone, second for android
if (e.cancel === e.index || e.cancel === true) {
//now you can use parameter e to switch/case
switch (e.index) {
case 0:
//Do something here
More details about click event object

try to use this Marcos to minimize out keystroke whole day. If you know any other Marcos which miss here please update in comments, Thank you.

Enjoy while code..!