Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Started with C and Objective-C

I am eventually wanting to program in Objective-C to write programs for OS X and possibly the iPhone. I do not have any direct experience with C and I come from a web programming background. I am much more familiar with java syntax than C and Objective C.

I am just looking for suggestions on how to get started. It looks like I need to just start with C (I do not yet have a Mac computer powerful enough for programming, so it would be nice to start with C on the Windows platform anyway (information about programming environments would be helpful too, I am used to eclipse)). I am just looking for book recommendations, online tutorials or any other pointers to keep in mind. Keep in mind though that my end goal is to work with Objective-C, so is there anything I need to keep in mind when learning C, anything to watch out for, etc. Thanks for any input.

Update: The reason I am thinking I need to learn C first is that most of the tutorials that I have come across so far for Objective-C assume you already understand C syntax, which I do not fully. Are there better tutorials out there for me?

like image 877
Ryan Guill Avatar asked Jan 13 '09 14:01

Ryan Guill


People also ask

How do I get started with Objective-C?

Whenever you create a new file (File > New > File...), you are presented with a list of file templates. Choose Cocoa from the OS X section and select the Objective-C class template to create a new Objective-C class. Click Next to continue. Give the new class a name of Book and set its subclass to NSObject .

Should I learn Objective-C or C?

If you want to get work done, Objective-C is the way to go. Swift is the new kid on the block, but it's still a kid. If you want to get work done, Objective-C is the way to go. At the time of writing, Apple's software development kits are primarily written in C and Objective-C.

Is Objective-C compatible with C?

Objective-C is an object-oriented programming language that is a superset of C, as the name of the language might reveal. This means that any valid C program will compile with an Objective-C compiler. It derives all its non-object oriented syntax from C and its object oriented syntax from SmallTalk.

Is Objective-C and C the same?

Syntactically, Objective-C is an extension of C. So, some portion of Objective-C is exactly the same as C. Your experience of C would help learning such aspect of Objective-C. But the core part of Objective-C programming is made of Object Oriented class system, which you cannot find in C.


2 Answers

I don't entirely agree with unwind who says "C and Objective-C are different languages". Objective-C is a strict superset of C.

Of course he knows that - his point was that you don't need to completely master C before progressing onto Objective-C. I'll second that (and hopefully have clarified it).

But I do think it's worth getting some basics with C first, as most introductory texts on Objective-C will assume a basic knowledge.

I don't have any recommendations on that myself, but probably most internet based tutorials will be sufficient for that purpose (remember, you're not trying to master it at this stage). If you want to take it seriously, then "The C Programming Language" by K&R is the classic text.

When you you can do some basic hello world programs in C, and understand the type system, pointers and stuff - then pick up a copy of "Cocoa Programming for Mac OS X", by Aaron Hillegass. This is a book about Cocoa that covers Objective-C along the way, but it one of the best presented coverages of the language. It will assume you are coding on a Mac (it's in the context of Cocoa after all). You may be able to follow the pure language stuff using GCC on Windows, but I wouldn't recommend it.

If you're going to be working on a Mac eventually, then best to do it at this stage, IMHO. You say you don't have a Mac "powerful enough for programming", but anything that can run OS X would be fine to get your started.

like image 97
philsquared Avatar answered Sep 30 '22 11:09

philsquared


If you know java, obj-c will be easy for you (java was influenced a lot by obj-c.) Apple has great documentation, you can start here. I don't think you need to learn C before learning obj-c (sorry Joel).

You can use obj-c on windows if you get gcc. Also check out cocotron:

The Cocotron is an open source project which aims to implement a cross-platform Objective-C API similar to that described by Apple Inc.'s Cocoa documentation. This includes the AppKit, Foundation, Objective-C runtime and support APIs such as CoreGraphics and CoreFoundation.

With all the buzz about iPhone development, there are now dozens of obj-c books. Not sure how good they are, but a classic that I would suggest is Cocoa Programming from Mac OSX by Aaron Hillegass.

like image 36
lajos Avatar answered Sep 30 '22 10:09

lajos