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.

The iPhone SDK: Safari<br />

315<br />

C.2 Alternatives to <strong>Objective</strong>-C and Cocoa<br />

Out of the box, Xcode and the iPhone software development kit (SDK) support<br />

development of applications in C, C++, and their <strong>Objective</strong>-C-based variants, but this<br />

doesn’t mean they’re the only options open to developers. A number of third parties<br />

offer alternative development tools to suit the needs and backgrounds of almost<br />

any developer.<br />

Of these alternatives, a lot of attention has been concentrated on those that enable<br />

applications to be developed in scripting languages such as Lua or Ruby or that use<br />

technologies such as HTML, Cascading Style Sheets (CSS), and JavaScript, which are<br />

more familiar to client-side web developers. It’s commonly perceived that these types<br />

of tools can offer a quicker and perhaps more productive work environment, much in<br />

the way that <strong>Objective</strong>-C and other Smalltalk-inspired languages were considered an<br />

improvement over C and C++.<br />

C.2.1<br />

Close to home: <strong>Objective</strong>-C++ and plain old C or C++<br />

If you’ve developed for another mobile platform, you likely have some background in<br />

C or C++. A lot of third-party support libraries for a magnitude of purposes, such as<br />

speech synthesis, physics engines, communication, and image analysis, to name a few,<br />

are also developed in these languages.<br />

Xcode can compile C (.c) or C++ (.cpp) source code in an iPhone project just as<br />

easily as it can compile <strong>Objective</strong>-C (.m) files. Simply add the files to your project and<br />

allow Xcode to build your project as normal. A number of the key frameworks in iOS,<br />

such as Core Graphics, are C-based APIs, so you’re already familiar with integrating<br />

code developed in C or C++ with an <strong>Objective</strong>-C project.<br />

Unlike Mac OS X, though, iOS doesn’t provide a C-based API for creating GUIs<br />

(there’s no equivalent of Carbon). This means that unless you’re interested in developing<br />

a completely custom UI with OpenGL (another C-based API), your use of C or<br />

C++ source code will probably be restricted to behind-the-scenes logic, which will then<br />

be interfaced to a UI written in <strong>Objective</strong>-C. This isn’t a bad approach if you want to<br />

share a core set of logic across a number of platforms that support development in C<br />

or C++, such as iOS, Android, Symbian, and Windows Mobile. You can develop your<br />

core logic with C or C++ and then wrap a platform-specific UI layer around it for each<br />

platform you want to support.<br />

<strong>Objective</strong>-C++ is interesting because it’s, quite literally, the object-oriented features<br />

of <strong>Objective</strong>-C applied on top of the C++, not C, programming language. This combination<br />

leads to some interesting side effects. As an example, it isn’t possible to derive a<br />

C++ class from an <strong>Objective</strong>-C class, because no attempt was made to unify their distinct<br />

type systems.<br />

C.3 The iPhone SDK: Safari<br />

When the original iPhone was released, the only way to extend the platform was by<br />

deploying web-based applications. As an Apple press release of the time noted:

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

Saved successfully!

Ooh no, something went wrong!