Appcelerator Developer Blog

Beginners: Javascript Objects and Arrays

If you’re new to Titanium, first of all Welcome!

If you are just starting out with Javascript, this post will definitely help you understand two very important features of Javascript: Object and Array literals. Knowing their syntax will not only help you understand how Titanium works, but will speed up your understanding of CommonJS and JSON.

Perhaps you don’t know them by name, but the truth is that when you work with Javascript, you’re working with Objects all the time without realizing it. Take a look at the following example:

var carmake='Honda';
console.log(carmake.toUpperCase());

Where did toUpperCase come from? Here you have used an Object. Every time you create a String variable, you’re actually creating a String Object. This object has properties and methods, toUpperCase being just one of them. More details about the String object here. Get used to the word “Object”, because is the foundation of modern programming.


Object Literals

Object Literals are Objects that you create on the fly. The syntax for Object literals is simple:

  • Enclose it in curly brackets
  • separate properties with comma
  • separate keys and values with a colon
var person={
    name: 'jack',
    email: 'jack@ctu.com',
    twitter: '@jackb_ctu'
};

To access the values on this object, you can use “dot notation”, that is, the name of the object, a dot, and the name of the property.

console.log(person.name);
console.log(person.twitter);


Array Literals

Just like objects, arrays can also be created on the fly. The syntax rules for array literals:

  • Enclose it in square brackets
  • separate each element with comma
var arr=[
            'value1',
            'value2',
            'value3'
        ];

To access the values, you use a numerical index:

console.log(arr[0]);


The fun part

The power of Javascript Object and Array literals comes by combining them. A combination of Objects and Arrays make up a complex, multidimensional object.


Array literal with two objects as values

var arr=[
           {key1:'value1'},
           {key2:'value2'}
        ];
console.log(arr[0].key1);


Object literal with a two-item array as property

var obj={
            key:[
                   'value1',
                   'value2'
                ]
        };
console.log(obj.key[1]);


Array literal with one property that is a two-item array

var arr=[
           {
              key:[
                    'value1',
                    'value2'
                  ]
            }
         ];
console.log(arr[0].key[1]);

This syntax is very popular in today’s web services and perhaps you’ve heard of JSON (Javascript Object Notation). JSON is an implementation of this syntax designed to be a way of transporting data across the Internet.


Applying these concepts in Titanium

Titanium itself is a JavaScript SDK (Software Development Kit) that works as an “Object Factory”. This means that it has methods that generate Objects, and most of the times these methods receive Objects as arguments. It sounds more confusing than it is.

var win=Titanium.UI.createWindow({
    backgroundColor: '#fff',
    fullscreen: true
})

The result of this operation is a Titanium Window Object stored in the variable win. However, the createWindow method received an object as argument, and object with the properties backgroundColor and fullscreen. As you can see, knowing how an object is constructed allows you to understand that the createWindow() and the toUpperCase() methods are very similar. The difference is that you are sending an Object Literal to the createWindow method.

A full description of Titanium’s objects can be found at Titanium API Documentation.

I hope this short tutorial can help you understand Titanium’s syntax and how powerful it can be.

Codestrong!


Making it easy to port your apps to Tizen: A promotion from appbackr for Titanium developers

The following guest spot is from Trevor Cornwell, Founder and CEO at appbackr. You can follow him on Twitter at @trevorcornwell


Titanium makes it easy for developers to build mobile apps and publish them across platforms. It is a big step forward. appbackr is focused on motivating more developers to build across newly emerging platforms.

Encouraging distribution to other platforms is challenging because of a few basic reasons, starting with “Is it worth my time to port to any given new platform?” Because selling apps, like any content, is a matter of aggregating medium and long-tail users, we believe that porting to a new platform makes sense. Except that there are tedious sign-up processes, long contracts that may subsume distribution rights and unknown SDKs, which all create just enough friction to make the process eminently skippable.

And the problem exists on the other side: new platforms want great apps, but not necessarily sub-prime, chop-shop apps.

So how do great developers with the best new apps meet great, emerging platforms efficiently?

appbackr is providing a promotion to Titanium developers to help! We’ve made it possible for every app that you create to get scored for quality and relevance on a 1 to 10 scale. The best apps receive tools and a guarantee number of downloads based on the store’s needs and how well your app fits.

As part of this promotion, once you build your app on Titanium, you can see the score and your offer. With the announcement of Titanium’s support of Tizen, appbackr has scored every app and Titanium developers will be receiving a simple 3-step process for porting to Tizen and getting a minimum guarantee for your app.

You can also sign on to Xchange and track your installs on one dashboard and even consolidate payments so you don’t have to provide your bank account information to every new platform that asks for it.

Why Tizen? This is a chance to have your app, live, right from the start of a brand-new operating system built on HTML5 and part of the Linux Foundation. It has heavy support from Samsung, Intel and major carriers around the world.

And once your app is live in Tizen, we can give you additional offers like free translation into launch country languages, and even offers to port to additional HTML5 platforms that are relevant to your app.

You made a great decision building with Titanium. Your app is ready to go in Tizen. Now, submit it through Xchange and receive the financial incentives that your app deserves.


Featured Developers – OpenRest

OpenRestToday’s featured developer story comes from the guys at OpenRest. OpenRest was founded in 2010 with the intent of revolutionizing mobile online food ordering. With the help of Titanium, Danny Leshem and Yoav Amit have delivered over 300 restaurant apps. Read more about their story and how they’re leveraging Titanium.

Interview with Danny Leshem and Yoav Amit from OpenRest

What is your background as mobile developers?

OpenRest was founded by Danny Leshem and Yoav Amit in late 2010 in order to revolutionize online food ordering. The company originally focused on web development, but quickly realized that the future of the business was in mobile and that a tremendous opportunity exists for great products in this field.

With an amazing team and a clear vision, OpenRest entered the mobile development world in late 2011 and never looked back. We currently have over 300 restaurant apps live on the appstore.

All software developers at OpenRest have a strong background in writing enterprise systems, from embedded code that’s executed on millions of TVs worldwide to security products that are now part of Microsoft’s enterprise solutions. We look for developers who see new programming languages and new platforms as opportunities and not as barriers, which may be the reason why we do things a bit differently.

As the name suggests, OpenRest strives on an open atmosphere. New ideas are implemented and released just as quickly as they are brought up, in two week sprints. We believe in giving back to the development community and encourage our developers to answer questions in forums and to open-source our internal non-core tools and libraries (Github repo). OpenRest’s R&D is in sunny Israel, “the startup nation” – our office has a great view of the Tel Aviv beach.

So tell us a little bit about your apps

OpenRest builds the smartest online ordering portals. Simply put, our platform lets anyone operate their own “Seamless” or “GrubHub” like food ordering portal. Our clients are local food portals that see the value in having the best technology and in offering their users the best experience, all under their own brand. Obviously, mobile apps are an important part of the platform.

Furthermore, our product also lets portal owners create white-label online ordering websites and mobile apps for the restaurants they service. Using a simple graphical interface, portal owners enter the restaurant’s information, customize its design, upload images and a few clicks later a unique restaurant app is generated and distributed to the App Store and to Google Play. It’s as simple as that.

Our existing clients in Israel, Belgium, Canada, the UK and the US use this platform to create and distribute their portal apps, as well as hundreds of white-label restaurant apps. Every day, thousands of people order food deliveries and take-outs using our apps and websites.

Why did you pick Titanium for your app development?

The first version of our restaurant app was actually developed in pure Objective C, and we released several apps based on it.

When we decided to expand to more platforms, we started looking for frameworks that would allow us to share code between iOS, Android, and the web. We didn’t mind dumping our existing code as we figured that in the long run the time saved by a unified codebase would well cover the one-time cost of the rewrite.

Our top requirements from such framework were:

  • Performance: in online ordering, a fluid user experience directly correlates to revenues. This meant we had to focus on native frameworks rather than on HTML5.
  • Multi-platform: at the very least iOS and Android (extra bonus points for web).
  • Support: large and active development community (extra bonus points for open-source).

We found Titanium to be a perfect fit.

What were some of the highlights of Titanium development for you?

First and foremost, by implementing a Model-View-Presenter design our entire line of client-side products is now based on a unified JavaScript codebase: native mobile (utilizing Titanium), mobile-web (utilizing “The M Project”) and desktop web (utilizing jQuery). This translates to huge time savings that allow us to focus on innovation rather than on maintenance.

Second, the large community behind Titanium means that we are never left hanging. On rare occasions when we didn’t get answers from the community, a quick look at Titanium’s source code was enough.

Last, Titanium enabled us to create self updating native apps. We use this extensively during development to eliminate the constant need for long and tiresome deployments, and in our production Android apps.

We plan to write a series of technical posts on all of this in our Tech Blog, so stay tuned.

How many people worked on it? How long did it take to design, implement, and test?

Our app development is ongoing as we continuously add more features, and our unified codebase approach means that all OpenRest developers occasionally write Titanium code. Still, the majority of our Titanium-specific code was written by two people over the course of a few months.

It takes us far less time to design and implement apps in JavaScript using Titanium than in standard native code – mainly thanks to code sharing, but also because it is much easier to find good JavaScript resources and developers.

What resources did you use to learn and develop with Titanium?

Coming from native development background, we found Titanium to be very easy and intuitive to learn.

We started by studying the KitchenSink code and various online tutorials, and today we mainly use the API documentation, the developer forums and StackOverflow. When needed, we also dive into the native code.

All our developers follow Appcelerator’s blog for platform updates.

Do you have plans for updates to the OpenRest Platform or future Titanium apps? Care to share some details?

We continuously update our platform and our apps with new features, designs and bug fixes requested by our clients. Right now we’re closing our mobile-web version, which will also be integrated into several 3rd-party apps that wish to leverage our affiliate program.

Looking forward we plan to expand our mobile apps beyond online ordering, to help our clients keep their commanding positions as technology leaders in their respective markets. We’ll also be the first to support any new platform – for that we are counting on Titanium’s quick response to new emerging technologies.

Any additional thoughts or notes on Titanium development?

Our apps keep pushing the limits for performance, and lately we started feeling that we have reached the barrier with our Titanium-based apps. We are anxiously waiting for Titanium’s new ListView implementation which should boost performance across all our apps. We’d also love to see official cross-platform support for background threads in future versions of Titanium, e.g. based on the web worker interface.

Another feature that all Titanium users should benefit from are ready-made integrations with mobile ad networks. Effective marketing is a major contributor to mobile apps’ success, so giving Titanium developers the tools to support such efforts would be highly advantageous for everyone.

Why is being a mobile developer the coolest job on the planet?

On the grand scheme of things, mobile developers can instantly share their creations with millions of people by simply uploading an app to the appstore. Mobile is the “new frontier” for software developers, and everyone (and we mean EVERYONE) has “the next awesome idea for a mobile app”. This is unparalleled in our history.

On a day to day basis, it’s just fun to wake up in the morning, meet clients, designers and marketing people, and create cool apps that your users love (and they keep telling you that in appstore rankings). There’s just something special about sitting somewhere and noticing a random person take out their iPhone and casually use something you created. Oh, and the pay is great! :)

Developing mobile apps is much more challenging than, say, developing standard web applications. In fact, it has a lot in common with writing embedded code when it comes to the limitations you have to face. Finding creative solutions for these limitations is a big part of the fun.

What is the most exciting problem that you’ve attacked as a mobile developer?

We want our apps to deliver an amazing experience as it directly correlates to usage and popularity, but achieving this on mobile devices is difficult due to limitations in screen size, processing power and network latency. Alas, this doesn’t prevent our users from having extremely high expectations!

Getting there requires us to continuously combine good-old-fashioned code optimizations and a variety of UX tricks. It’s a problem that can’t be solved by simply programming the right way or having a great design, but by finding smart ways to combine the two. It requires all the brains in the company working together to find creative solutions.

What advice do you have for companies that want to delight their users with mobile?

First, go native. The future of mobile apps may (or may not) be HTML5, but delivering the best experience to your users right now requires you to write native apps (Titanium apps included, of course)

Second, don’t underestimate the power of design. Good programming is only half of what makes a great app. For your app to spread like wildfire, for people to talk about it, use it again and again and give it high ratings – the app must be beautiful. And that requires great designers… and just a bit of luck :)

Finally, you must have good analytics. Define success metrics, measure user engagement and continuously identify your app’s hot spots. Understand how users actually use the app, and use this knowledge to make their experience better.

What inspires you about the future of mobile?

The rate of change is simply overwhelming. Do you realize that the first iPhone was released less than 6 years ago, and that 3 years ago we didn’t have iPads? Every year brings new paradigm shifting technologies that rapidly spread worldwide. These are very exciting times to be living in!

Do you have some links you would like to share?

OpenRest website
Blog
Tech blog
Facebook
Twitter

Do you have an interesting story to tell about your development on Titanium? We would love to hear it. Drop us a line at community@appcelerator.com and tell us more.


Adding PHP, Ruby or Python support to Titanium Studio

As part of our latest 3.1.0 release, we slimmed down Titanium Studio by making certain pieces optional installs, namely the support for server-side languages. Fear not! It’s easy to add them back in again:

  1. Launch Titanium Studio;
  2. Go to Help > Install New Software…
  3. Enter the following URL in the “Work with: ” field:
  4. Check the top level node in the table and go through the wizard to install.

 


Announcing Titanium 3.1 and Node.ACS Production Releases

It’s all about enterprise connectivity, performance and new platforms

We have kept ourselves pretty busy here at Appcelerator over the last couple of months. Today we are excited to announce a major release for both the Titanium and Cloud products: Titanium Studio and SDK 3.1 and Node.ACS GA.

Titanium 3.1

In the 3.1 release we focused on 3 key areas: performance optimization, APIs, and new platform support. Please see the release notes for further details.

Performance Optimization

  • We spent significant time optimizing the core architecture of Titanium, focusing on object creation, window creation, image usage and other key areas with broad applicability. For these integral pieces:
    • iOS apps will run on average 20% faster over our 3.0.0 release
    • Android apps will run on average 36% faster over our 3.0.0 release
  • We have also released the ListView component which functions several times faster than the TableView component.

In short you should notice a performance improvement for all of your apps running under 3.1.0.

Alloy Updates

We have also been hard at work extending Alloy, our MVC framework. The amount of positive feedback that we have received on Alloy has been outstanding, and It is being adopted at a rate faster than we ever expected.

Titanium Studio 3.1.0 now supports the following features for Alloy apps:

  • Content assist
  • Debugging

APIs

ListView
This release introduces ListView, a new Titanium component to replace the existing TableView. ListView uses a data-oriented approach versus TableView’s view-oriented approach which greatly improves performance.

iOS EventKit UI Framework
The iOS EventKit framework, allowing access to calendar events and reminders, is now available from within Titanium.

Modules

In this release we have also released some new modules. Specifically:

  • Newsstand (iOS): Publish a magazine or periodical with Titanium
  • NFC (Android): Read NFC (Near-Field Communication) tags from inside Titanium applications.
  • Facebook V3 (Android, iOS) API support

New Platforms

3.1 contains support for mobile platforms beyond iOS and Android:

Tizen
Tizen is an open source, standards-based, mobile software platform supported by leading mobile operators and device manufacturers including Samsung and Intel. It is now a full member of the Titanium family, supported in Titanium 3.1.0 Studio and SDK.

BlackBerry
Our Blackberry 10 support is now in beta. Please begin building apps for the BlackBerry 10 and provide us with feedback. In this beta release we believe there are the majority of features to get you started, including Alloy support, MapView, WebView, Database, Localization Support, and much, much more.

To use the BlackBerry beta, you must download a 3.2 version of the Titanium SDK from the continuous integration (CI) server. Note that the 3.2 builds have not received any testing except for the BlackBerry beta. For all other platforms, these builds should be regarded as unstable builds

Downloading 3.1.0

For new users, download Titanium 3.1 by clicking here.

For existing Titanium Studio users, you will be prompted to update automatically on the next restart. You can also manually check for updates by selecting the “Check for Titanium SDK Updates” from the “Help” menu within Titanium Studio.

If you previously installed the Release Candidate versions of the Titanium CLI and Alloy, that is, npm install titanium@3.1.0-cr and npm install alloy@1.1.0-cr, or any -beta or -cr packages, you need to first uninstall these components before installing or updating to 3.1.0.GA. The release notes contain specific instructions on how to do so.

Node.ACS version 1.0 (GA)

Node.ACS extends Appcelerator Cloud Services by providing the popular Node.JS development framework on the middle-tier. Using Node.ACS, you can implement and deploy server services using JavaScript on the Appcelerator Cloud. You can develop connectors to enterprise data back-ends like Oracle or Salesforce for your entire mobile app portfolio, extend the functionality of prebuilt services provided by Appcelerator Cloud Services (ACS) or simply use any of the 1000’s Node.JS modules published by the developer community.

As a developer, you will immediately realize the benefits of:

  • a single programming language (JavaScript) and development environment (Studio) for both client and server side code.
  • a single location to host your business and application logic
  • easy access to the ACS database and storage
  • an MVC framework for creating scalable Node.ACS apps
  • ability to update your Node.ACS app independently from your mobile app
  • reliable, scalable infrastructure for your backend

With Node.ACS, Appcelerator Cloud becomes a comprehensive MBaaS (Mobile Backend-as-a-Service) that any enterprise can use for deploying the server code for its mobile apps. Node.ACS will be available as part of the Appcelerator Platform offering. Node.ACS apps can be deployed both on the public Appcelerator Cloud and a Virtual Private Cloud.

Getting Started with Node.ACS

To start developing Node.ACS apps, use the resources below:

Note: if you were participating in the Node.ACS developer preview, see the Node.ACS Release Notes for instructions on how to migrate your Node.ACS apps.

As always I want to thank our 450,000 strong community of developers for your constant feedback and support.

Page 2 of 9012345...102030...Last »