As I'm learning Objective-C for iPhone, a friend is discouraging me by insisting that Objective-C is syntactically obtuse and missing many modern language features. Objective-C is usually described as being "close to the metal" and therefore more efficient, but in reality, he says, some of the heaviest iPhone games do not use Objective-C at all, but rather use C. Here is a related link for Mac itself, at least. This is in part because Objective-C is not particularly efficient, he argues.

Is it true that many/some popular/important apps for iPhone use straight C?


I?ve written two 2D games for the iPhone using OpenGL ES and found the Objective-C performance cost to be almost negligible. There are a few corner cases where one has to resort to plain C or ? God forbid ? C++, but over 90 % of the time I could stick to Objective-C. Which is a much more convenient language than C and much safer and simpler language than C++. I think that the vast majority of applications for the iPhone are written using Objective-C. If a game uses C++, IMHO it?s mainly because of its developers are already familiar with it, not because of performance reasons.


This is utter rubbish for the most part (certainly the assertion that "most" iPhone developers don't use objective-c anyway).

Some edge-case apps (or cross-platform ones) probably only use C but most of the toolkit is in Objective-C so that where most people work. It's far easier to be productive in Objective-C on the iPhone that anywhere else as that's where all the fluffy high-level abstractions get implemented.


I have coded iPhone games in C++ that just use an Objective-C stub for calling the C++ classes (in fact, I do 99% of my iPhone game dev in Windows). So for game dev, an in-depth knowledge of Obj-C is not a necessity. I have worked at a game studio where we just used Mac's for distribution and hardware testing, everything else was done under Vis Studio using C++.

If you want to use Cocoa though, you're gonna need to use it.

In the end though, you should learn it simply because it's a cool language, once you get over the initial shock of the horrible-looking syntax.


It is both true and false.

There are lots of applications that have been implemented using objective-c only. Objective-c has its advantages over c and in some cases advantages over c++. Most of iPhone APIs are also objective-c so when you start from scratch it might be easier to implement the whole app using objective-c. But first you have to forget your fear about new/different programming languages.

On the other hand lots of applications (especially games) take advantage of c/c++ directly. This is because there is lots of existing code base in c/c++ that is being reused (game engines, physics engines, rendering engines etc.). OpenGL API is also in c, so for OpenGL applications c/c++ might be a natural choice. C/c++ lets you to optimize the performance critical parts better.


For games? Yes, you barely use any Objective-C in those, it's mostly going to be OpenGL, at least for drawing graphics. Using OpenGL you're riding as close to the rails as possible so you get great graphic performance while still enabling the user to have a high level of interactivity.

For any other type of app? Well, I suppose you could implement a Twitter client using OpenGL, but that wouldn't be a very good way to spend your time. Pretty much every non-game category is 99% Objective-C and Cocoa.

However if his main argument was complaining about the syntax, just slap him. It's fine after playing around with it for a bit.


I'm not an expert in terms of games (those will probably be written in C/C++ for the most part), but most applications for the iPhone are written in Objective C. It's a very comfortable language in my opinion and not at all annoying. The frameworks for Objective C are very well designed and help you write programs with very few effort.

But you'll have to know C to work with Objective C, as it is based on C (as is C++).


There is an article by Matt Gallagher on "Objective-C's niche: why it survives in a world of alternatives". This should clear your doubt somehow!


I don't know if that's true, but I doubt it. I found Objective-C to be very easy to learn and to be a fairly consistent language. Contrast this with C++, anyone?

You need Objective-C to integrate with all the iPhone frameworks, so it is absoluteley out of scope to use C only.


Yes - most of the games are probably written with OpenGL (so C or C++). The other possibility is that some apps were written in flash or .Net (MonoTouch) and compiled down to binary that works on the iPhone. Having built several iPhone apps, I can say that the objective-C syntax does get easier - though I still find the language trying. And I hate XCode.


Your question and his assertion are two different beasts.

Many iPhone apps use pure-C subsystems as well as Objective-C, for valid performance reasons.

An app must create a specific Objective-C object just to get started, so an app which didn't use Objective-C at all wouldn't run at all (and thus wouldn't make it through review and onto the App Store).

Objective-C builds atop C, so learning Objective-C means you're learning (enough) C anyway. Don't let your friend's delusions leak all over your own confidence in your ability to learn!


It depends on if you plan to use Cocoa Touch and the Apple tools. If you're going to create all your own custom UI then you can use whatever makes you happy; but to use Cocoa Touch, Interface Builder, etc you're going to need to understand Objective-C (really not that hard) as well as the Cocoa API (which I found elegant once I got into it).

Standford posts their iPhone undergrad course on iTunes U; it's a great intro to both the language and API.


you will most likely use c,c++ for low level stuff but you will still need obj-C for higher level stuf


I've been making games for close to 15 years on the consoles and PCs. I am new to the iPhone, but as someone that has spent years worrying about performance, I can tell you that the hit you will take with objective-c is anything but "negligible". Making function calls (message passing) is a big hit, don't let anyone fool you. Making a obj-c call is 5 times slower than making a virtual function call in c++, but many times slower then making a strait function call (we avoided virtual functions in console games for this very reason).

Also remember that every member variable that is part of an obj-c class gets wrapped in an accessor function, so just accessing a variable from another class invokes a obj-c function call and due to the nature of obj-c, the compiler can't optimize accessor functions away like it can in c/c++.

Stay far away from NSArray and the like, these are very slow. I use stl containers for everything. Mixing obj-c and c/c++ is easy and seamless. Just create .mm files instead of .m files and you're good to go with the stl. If your project already has .m files, just rename them.

I like objective-c and enjoy programing in it, but I treat it like a scripting language. I code a lot of the game logic in obj-c, but ALL the backend "engine" functions are c/c++.


There is, for example, a fast and lightweight 2D rigid body physics library in C that can be used for iPhone game development as well: chipmunk.