01.02.2014 Views

Objective-C Fundamentals

Objective-C Fundamentals

Objective-C Fundamentals

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

320 APPENDIX C Alternatives to <strong>Objective</strong>-C<br />

applications in HTML, CSS, and JavaScript without having to give up too much crossplatform<br />

portability.<br />

A similar solution is Titanium Mobile (www.appcelerator.com/products/titaniummobile-application-development/).<br />

A unique feature of Titanium is that it provides<br />

access to the entire iPhone or Android UI feature set: table views, scroll views, native<br />

buttons, switches, tabs, and popovers can all be accessed from the JavaScript in a Titanium<br />

Mobile–based application.<br />

With both solutions, because source code is available, if you find a device feature<br />

not exposed to JavaScript, and you’re comfortable with writing a little <strong>Objective</strong>-C or<br />

C, you can easily provide a JavaScript callable wrapper for the feature in question and<br />

produce your own application-specific variant of the solution.<br />

Ultimately, the decision of web versus native iPhone development may come down<br />

to your own personal experience and comfort levels. If you’re a web developer, learning<br />

how to optimize your existing web pages for viewing on the iPhone may be the<br />

quickest route forward. If you’re a long-time C, C++, C#, or even J2ME developer, taking<br />

the time to learn <strong>Objective</strong>-C and Cocoa to build native applications may be more<br />

rewarding and open the possibility of code reuse from previous projects.<br />

C.4 Scripting languages: Lua and Ruby<br />

If an <strong>Objective</strong>-C-based application can be developed to host content written in<br />

HTML, CSS, and JavaScript, you may wonder if it’s possible to develop similar shells to<br />

enable development of applications in other popular scripting languages such as<br />

Python, Ruby, or Lua. The resounding answer is, yes—although the path to App Store<br />

acceptance hasn’t always been clear or straightforward in such cases.<br />

One such product is the Corona SDK product from Ansca Mobile (www.anscamoble.<br />

com). Corona enables a developer to write an application in the Lua scripting language<br />

and place it in a predeveloped native application that performs a task similar to<br />

what PhoneGap did for JavaScript.<br />

Although PhoneGap is more focused on enabling web-based content, the focus of<br />

Corona is arguably in gaming, as OpenGL-ES and similar game technologies are used<br />

heavily in the APIs the Corona SDK exposes to your Lua script.<br />

The Corona website offers the contents of listing C.2 as an example of the<br />

<strong>Objective</strong>-C source code required to draw an image onto the screen using OpenGL-ES.<br />

Although the source code is arguably worse than it needs to be, it’s hard to deny the<br />

potential productivity gains once you compare it to the one line of Lua source code<br />

required in a Corona application to perform the same task: display.newImage<br />

("myImage.jpg", 0, 0).<br />

Listing C.2<br />

Drawing an image onscreen with OpenGL and <strong>Objective</strong>-C<br />

NSString *path = [[NSBundle mainBundle] pathForResource:@"myImage"<br />

ofType:@"jpg"];<br />

NSData *texData= [[NSData alloc] initWithContentsOfFile:path];<br />

UIImage *image = [[UIImage alloc] initWithData:texData];

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!