PDA

View Full Version : C in iPhone




fernandovalente
Apr 11, 2009, 06:11 PM
May I use C or at least some C functions in iPhone programing.



dejo
Apr 11, 2009, 07:45 PM
Of course you can. Objective-C is just a superset of C.

fernandovalente
Apr 12, 2009, 02:12 PM
Of course you can. Objective-C is just a superset of C.

Thank you! Two more questions. May I use only C(without use the superset of C)? Will my app become unstable?

MacDonaldsd
Apr 12, 2009, 02:23 PM
Thank you! Two more questions. May I use only C(without use the superset of C)? Will my app become unstable?

You need to write the skeleton of the application in Objective-C, as the OS communicates to the app using Objective-C only. Also all of the iPhone UI is done using Objective-C.

If you code what ever you do properly, it will have no effect on stability.

mccannmarc
Apr 12, 2009, 02:34 PM
The source code for Wolfenstein on the iPhone is all C they have just used the AppDelegate as an entry point to the app and to call their C functions to run the game. (Obviously they use Obj-C for iPhone specific stuff such as accelerometer etc but the core of the game is all C)

In fact the code is a very interesting read to anyone who is mainly a C developer as it demonstrates the use of heavy C code on the iPhone and would answer most of your questions

firewood
Apr 12, 2009, 03:09 PM
May I use only C(without use the superset of C)? Will my app become unstable?

You can use straight ANSI C as long as your app doesn't use require any UI interaction (any user input or window output), and runs less than 20 seconds.

For instance, you can write an app that makes a posix network connection, downloads some data and plays a PCM sound waveform without writing any Objective C (or maybe 3 or 4 lines of it), other than in the templates.

Otherwise you will need to use some Objective-C to access the UIKit frameworks for any UI (touches, accelerometer, windows, views, etc.), and the main run loop.