Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

iPhone and C

Can the iPhone run programs written in just C? Do any other languages have to be involved?

iMac 2.66 GHz standard configuration (April 2008), Mac OS X (10.6.1), iPod Touch 1st Generation OS 3.1, D-link DIR-625 router, iLife 09, iWork 09

Posted on Oct 7, 2009 11:51 AM

Reply
20 replies

Oct 7, 2009 11:46 PM in response to musicwind95

Keep in mind that, while what has been said here (about iPhone developers needing to use Objective-C) is true, Objective-C is simply an extension to C, so in that sense I would think that an iPhone app could be written in just C. After all, you are writing C every time you use Objective-C, so you could write an app in Objective-C that doesn't make use of any of Objective-C's extensions to the C language, and you would, in effect, be writing an app in C. I hope someone with more experience will correct me here if I've said anything inaccurate (I don't really know anything about iPhone development in particular), but if you're asking if you have to know a language other than C to program an iPhone app, I would think that the answer would technically be no, since it uses Objective-C, and C is part of Objective-C.

Oct 8, 2009 8:33 AM in response to musicwind95

I don't know how Objecitve-C relates to C


That's what I was trying to explain in the last post -- Objective-C is simply a superset of C, which means it's simply C with some extra functionality added -- C plus a little extra, in other words. So, what I was trying to say is that since iPhone development supports Objective-C, if you want to program in C, then all you have to do is open a project and start programming in C. If it supports Objective-C, then it will compile C fine.

Again, though, I hope someone who knows iPhone development better will come along and tell you more of what you want to know about iPhone development in specific, but I wanted to point out that much. Best of luck with everything.

P.S. -- if you decide you want to learn the extensions to C that Objective-C provides, then I would pick up the Apress book Learn Objective-C on the Mac. It doesn't teach the C language part of Objective-C, just the extensions to C that Objective-C provides (just the extra stuff, in other words), which is perfect if you already know C -- it will teach you Objective-C without having to flip through an entire primer on C. I've found it to be a very good book.

Oct 8, 2009 2:58 PM in response to Tron55555

Tron55555 wrote:
That's what I was trying to explain in the last post -- Objective-C is simply a superset of C, which means it's simply C with some extra functionality added -- C plus a little extra, in other words. So, what I was trying to say is that since iPhone development supports Objective-C, if you want to program in C, then all you have to do is open a project and start programming in C. If it supports Objective-C, then it will compile C fine.

Again, though, I hope someone who knows iPhone development better will come along and tell you more of what you want to know about iPhone development in specific, but I wanted to point out that much. Best of luck with everything.


I understand what you're saying, and it's true to a certain extent. But in this context I think it's a bit of an oversimplification and perhaps misleading to the original poster.

Development for the iPhone requires the use of the UIKit Framework... which is a Cocoa framework... which makes use of Objective-C. So in order to interact with and make use of the framework you would need to write some amount of Obj-C code. In other words, much of the basic functionality needed by even the simplest of iPhone apps is not easily or directly accessible via plain C.

Sure, you could probably try to reduce your use of Obj-C to the bare minimum and do as much as possible in plain C... but I expect that it would be extremely painful and frustrating. You would most likely end up bypassing many of the great features that Obj-C and Cocoa offer and you'd probably also risk introducing bugs in your app that use of the provided Cocoa classes would avoid.

In my opinion, if you're truly wanting to invest your time creating iPhone apps you would be far better off in the long run (and even in the short term) to take the plunge into Objective-C and Cocoa now... rather than trying to band-aid something together with C in order to avoid having to learn the concepts of Obj-C and Cocoa.

Steve

Oct 8, 2009 11:56 PM in response to Steve Herman1

I understand what you're saying, and it's true to a certain extent. But in this context I think it's a bit of an oversimplification and perhaps misleading to the original poster.


Fair enough -- that's why I was hoping someone with more experience would come by. Learned a bit from your post myself, so thanks.

In my opinion, if you're truly wanting to invest your time creating iPhone apps you would be far better off in the long run (and even in the short term) to take the plunge into Objective-C and Cocoa now... rather than trying to band-aid something together with C in order to avoid having to learn the concepts of Obj-C and Cocoa.


No arguments there. I think the main point I was trying to get across to musicwind was that C and Objective-C are not separate languages, and I wasn't sure if he knew that from his post saying he didn't know the relationship between the two languages. But, from the info in your post, it sounds like your right about it giving the wrong impression, so thanks for chiming in. Anyways, I definitely agree that Objective-C is worth taking the time to learn.

Best of luck with your iPhone development, musicwind!

Oct 9, 2009 6:21 AM in response to musicwind95

So on the path to iPhone development, after learning C what should I pursue? I'm considering either going to Objective-C, a book that is targeted towards iPhone dev. and so will cover both ObjC and Cocoa, or a book on plain Cocoa first?


This is something I actually do know enough about to help with. My experience is with Mac Development, not iPhone Development, but whether Mac or iPhone, the next thing to do after getting a basic understanding of C (which is definitely step 1) is Objective-C. You probably are aware of this, but unlike Objective-C, Cocoa is not a language -- it's a framework, and since Objective-C is the language you use to make use of Cocoa's features, it is definitely practical to understand how that language works before you move to Cocoa. The Apress Mac/iPhone development book series supports this idea -- they recommend the same thing -- first C, then Objective-C, then Cocoa.

The first book in this Apress series, the one that they recommend you start with, is called +Learn C on the Mac+, and I agree -- if you want to brush up on your C skills (or if you are learning C from scratch for that matter), this is a great book (I own it). Next, they recommend you move from C to the second book in the series, which is +Learn Objective-C on the Mac+ -- I own this book as well, and it's also great. However, if you don't know C then you can't just start with this book, because it only teaches the parts of Objective-C that are extensions to C -- it expects that you already know C, and you won't be able to program in Objective-C without that knowledge. Finally, they recommend that you move from Objective-C to their third book, which is called +Learn Cocoa on the Mac+ -- I don't own this book (yet), but judging from the other two, I'm sure it's good as well.

Once you have C, Objective-C, and Cocoa down (which are essential to development whether on the iPhone or on the Mac), Apress also has a series based on iPhone development in particular (the most novice of which I believe is called +Beginning iPhone Development: Exploring the iPhone SDK+ ). I recommend holding off on this book until you have an understanding of C, Objective-C, and Cocoa, because applying your knowledge and skills to iPhone development after you understand C/Objective-C/Cocoa should go very smoothly, but that's your call. I would definitely advise you, though, to take on Objective-C before Cocoa, and to make sure you have C down before either of those. Anyways, good luck with your programming ventures, and I hope this post was helpful to you.

-- Tron

Oct 9, 2009 3:16 PM in response to Tron55555

I'm currently looking at these books. I already have the "C Primer Plus" by Stephen Prata. One thing I'm thinking about is that after I finish that book (I'm about halfway through), should I go over K&R, which I do have a copy of? Or would that be redundant?

After that, I'm currently looking at Programming in Objective-C 2.0 (Second Edition) by Stephen G. Kochan, although I have added your recommendation for Objective-C for comparison.

After that, I'm wondering if "Learn Cocoa on the Mac" would be redundant alongside Mark and LaMarche, which others have recommended to me, and / or Hillegass.

Oct 9, 2009 11:42 PM in response to musicwind95

That's a good selection of books you've got picked out on Amazon. The only one I can't really speak about is the +C: A Reference Manual+ by Harbison and Steele -- I've considered buying it myself, but don't know anything about it. Other than that, let's start at the beginning:

In terms of C, I also have +C Primer Plus+. Now, I haven't gotten into yet, but from what I've seen of it and what I've heard, I think it's a great choice for learning C. You said you're halfway through it or so -- well I would imagine that once you're done that you'll be very sufficiently versed in C. I don't know what's being covered halfway through the book, but it's possible, given how large it is, that you've already covered plenty enough to move on to the next step. If you do decide to move on to Objective-C/Cocoa before you finish the primer, I recommend taking time out every now and then to continue with the primer and keep learning C.

As far as whether it would be redundant to go over K&R once you finish the primer, I would definitely say no. Now, you're probably not going to want to read it that thoroughly -- use your good sense, and if you feel like you already know a certain section that you are reading in K&R, then skim over that one. However, I would dare to say that it is never redundant to read K&R -- I haven't finished it myself, but it's been very helpful to me, and I've read lots of books on C. You said you already own K&R, but I also saw it in your shopping cart -- do you have the first edition or something, or did you just put it there for the sake of showing that it's one of the books you were considering reading? Also, I don't know much about the Answer Book companion to K&R, but I haven't found it to be necessary with my experience with K&R so far.

Now, when it comes time to move to Objective-C/Cocoa, you're right -- you can get a book like Hillegass that combines the to, and teaches you Objective-C in terms of Cocoa. This isn't a bad idea -- I just find it helpful to take on one thing at a time -- get Objective-C down and then worry about understanding it in terms of Cocoa, but that really depends on how you want to do it, and I can say that Hillegass is definitely a good book -- I own it (I own about fifty some books on programming, so I've got a good deal of them). If you get Hillegass, make sure you get the 3rd Edition, not the 2nd, which is still being sold right now -- you have the 3rd Edition in your cart, but just wanted to let you know. Hillegass will teach you Objective-C, but it does it in the context of Cocoa, which can be confusing, depending on who you are, so like I said, that depends on you. It's definitely a good one though.

However, I've got to say, as good as the Hillegass book is, I've found the the Apress series that I recommended in the last post to be even better (at least for the Objective-C book -- I haven't bought the Cocoa one yet). The Kochan book, +Programming in Objective-C 2.0+ (make sure you get the 2.0 one), I don't own, but it's supposed to be a good one, and it's really one of the only other options out there for us Objective-C doers. So that would probably be a good choice too -- the reason I recommend the Apress one is that I know (from experience, unlike with the Kochan) that it's a good book, and because I often find it helpful when reading through a series of material (like C -> Objective-C -> Cocoa) to stick to one series of books -- you get used to their way of doing and explaining things, and that can often be very helpful, but again, that depends on you.

Finally, to answer your last question, I don't think that any of the previously mentioned books would be redundant alongside the Mark and LeMarche iPhone book. Now, keep in mind that I don't own that book, so I can't say that for sure, but since it's directed at iPhone development, I would think it would go well separately from the others, so getting both it and an Objective-C/Cocoa book wouldn't be a bad idea. If you can only get one, then I would recommend an Objective-C/Cocoa book and not the iPhone one, simply because I don't know how much the iPhone one will actually cover Objective-C/Cocoa in a way that will be beneficial to someone new to it. I know it introduces you to the iPhone SDK, but that doesn't necessarily mean that it will introduce you to everything else needed to program on the iPhone (Objective-C and Cocoa, for instance). Besides, you can always go back and get it later, once you know C/Objective-C/Cocoa, at which time applying those skills to the iPhone should be relatively easy. Again, though, that's all up to you -- I'm just trying to throw in my input.

The only other thing worth mentioning is that, if you ever want another good book on C or some other programming language, the Sams Teach Yourself books are books that I've found to be very good. They don't have any on Objective-C/Cocoa or iPhone development, but their books on C are great.

Oct 11, 2009 4:33 AM in response to musicwind95

Well, it can never hurt to learn as much C as possible before taking that next step, but to be honest, you really don't need to know that much. That's my opinion, of course, and I'm not an expert with Objective-C, but I would feel very confident in telling you that, as long as you understand the basics of programming in C (variables, arrays, branching, loops, functions, and so forth), then you should be able to get started with Objective-C. It's also worth noting that it's a good idea to have a good understanding of C structs before moving on to Objective-C. An object in Objective-C is pretty much like a C struct with a little bit of extra code attached (or at least that's how the Apress book describes it), so understanding structs first can be helpful.

Basically, since Objective-C builds on C, the important thing is that you understand C syntax and structure, so that you will know what you are looking at when you see Objective-C code and so you can tell what parts of the code are simply C and what parts of it use extensions to the C language that are exclusive to Objective-C. Sometimes this will be easy, since a lot of ObjectiveC-specific features begin with an at sign (@), but not always, so it's good to be able to recognize C code and differentiate it from the new stuff you'll be learning in Objective-C. That's the most important thing I think. After that, it's always possible that you'll run into something in Objective-C that has roots in C that you never learned or don't understand, and if that happens, you can go back and crack open a C book and learn it.

So, I guess what I'm saying is, don't think your wasting time by pressing forward with C and waiting to get into Objective-C -- that's not a bad idea at all, but also don't be shy about moving on to Objective-C now if that's what you want to do. Like I said, as long as you have the basics of C down, it shouldn't be too rough.

As far as the documentation goes, I would say that it fits in wherever you want it to. That's probably not the answer you're looking for though, so let me elaborate. I've listed links to some good documentation guides below. I recommend using the books as the main source of your learning. They are put together in a way meant for just that. However, some of these documentation guides can be very helpful learning tools as well. I would recommend using them as supplements to your books. After ever few chapters in your book, skim through some of these guides if you want to see if you can find anything that wasn't in your book. More importantly, if something isn't being explained well enough in the book or you just feel like you need more info on it, try these. Of course, you could use the book as the supplement and learn straight from these, or you could read the books and the guides side by side if you have the patience. That's up to you. The books, the guides -- they are all just resources to help you get all this stuff under your belt, so use them as you feel appropriate.

I haven't checked out the following links in detail, but I'm pretty sure they all apply to what you're doing. There may be others, but I did a pretty exhaustive search for you on the Mac Dev Center. I couldn't find any ones directed specifically at the iPhone though. Anyways, the links will take you to the site where it will tell you the gist of the guide, and you can download the guide from that site if you decide you want it (except for the third one, which isn't a download -- the whole document is right there on the page since it's short). I'd bookmark them, or this thread, because they could come in handy later (and because it took me a while to find them all 🙂 ). Here they are:

[The Objective-C 2.0 Programming Language|http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ ObjectiveC/Introduction/introObjectiveC.html] -- a great guide for beginning Objective-C

[Object-Oriented Programming with Objective-C|https://developer.apple.com/mac/library/documentation/Cocoa/Concept ual/OOP_ObjC/Introduction/Introduction.html] -- another great guide for beginning Objective-C, and more based around object-oriented programming concepts, as you can tell from the name

[Learning Objective-C: A Primer|https://developer.apple.com/mac/library/referencelibrary/GettingStarted/ Learning Objective-C_APrimer/index.html] -- short and sweet (not a download like the others); good summary of some Objective-C concepts, but probably not the best place to start from scratch

[Cocoa Fundamentals Guide|https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Co coaFundamentals/Introduction/Introduction.html] -- a guide to the basics of the Cocoa framework; haven't really checked this one out, but you may find it helpful when you decide to jump into Cocoa

[Cocoa Application Tutorial|https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual /ObjCTutorial/01Introduction/01Introduction.html] -- another good guide for Cocoa basics

Please let me know if there's anything else I can try to help you with.

Oct 11, 2009 5:55 AM in response to musicwind95

Also, note Mihalis's post above that had a few links that will probably be helpful for you. I think one of them is the same as one of the ones I just gave you. I think the other ones are resources outside of the ADC documentation (other websites) that could be helpful, so check them out to if you haven't.

I didn't mention in my last post that, for the links I gave you, you don't have to download them once you get to that site (I just figured this out myself) -- you can click on the chapters individually and page through the document on the web site without downloading it. Or, you can click where it says PDF at the top right of the screen to download it.

Anyways, I wanted to add the following two links to the list:

[A Tour of Xcode|https://developer.apple.com/mac/library/documentation/DeveloperTools/Conc eptual/A Tour_of_Xcode/000-Introduction/qtintro.html] -- this is a good little document; I found that it's not so much an introduction to Xcode as it is a guide to making a sample Cocoa application; it takes you through the basics of making a traditional "Hello, World!" application using Xcode and Interface Builder

[Interface Builder User Guide|https://developer.apple.com/mac/library/documentation/DeveloperTools/Conc eptual/IB_UserGuide/Introduction/Introduction.html] -- this is a great introduction to Interface Builder (which, as you probably know, is the application you use to build the GUIs for your applications); it goes over all the basics (and some not-so-basics) of how to use Interface Builder, which is an important part of Cocoa development

I would take a quick run through the Xcode tour (the first link above) right before or during the very beginning of you experience with making Cocoa apps. Even with the simplicity of the "Hello, World!" app it has you create, you probably won't understand everything it has you doing, but that's okay -- it's a good way to get familiar with the basic process of creating a Cocoa app. You could also go back and reference it later any time you need a reminder about any part of this process.

The second link is something I would just reference as you need it. When you take the next step and start learning Objective-C, the book you are using will most likely (or definitely if it's the Apress one) not even have you develop applications with GUIs using Interface Builder. It will likely have you practice the Objective-C language using command-line utilities strictly in Xcode (the Foundation Tool template is the command-line utility that uses Objective-C, in case you're curious). This is a much better way to learn the language -- you won't have to worry about all the fancy stuff while you are still getting the concepts behind the actual language itself down, which is a good thing in my opinion. Then, when you get to the point in the book where it actually has you develop an app using the Cocoa Application template in Xcode, that's when you'll know you're getting into the GUIs and having to use Interface Builder and what not, and that's when I would take a quick run through the Xcode tour that I linked to above. Then, once you start using Interface Builder for those Cocoa apps, the second link should also prove helpful if you need to find out how to do something, or if you want a tutorial early on for how to use Interface Builder (although your book should probably teach you everything need to know about using Interface Builder in the context of Cocoa apps, when you get to that point in the book).

Best of luck, and let me know if you have any other questions.

iPhone and C

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.