Muhammad Hewedy
Muhammad Hewedy

Reputation: 30058

Objective-C and its relation to C

Actually, I am very new to Mobile programming, and need to take your opinions.

I am a Java Developer with a C background, and I need to start Learning Objective-C with a target to do mobile app for iPhone and to refresh my knowledge in C (as I know, Objective-C is a pure superset for C, ain't it?).

So, the question is, With objective C, can I achieve my two objectives which are again:

  1. Do mobile dev for iPhone refresh my
  2. refresh my knowledge with C

Upvotes: 1

Views: 337

Answers (6)

John Smith
John Smith

Reputation: 12797

Objective C is another object oriented extension of C. Everything you know in C will work.

The best document to understand Objective C is

http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ObjectiveC/ObjC.pdf

You can do a lot with just C but you will be severely crippled. Every feature of C works in Obj-C.

If you really enjoy a world of hurt you could consider Objective-C++ which combines both C++ and objective-C

Upvotes: 4

Randall
Randall

Reputation: 14839

In my experience with mac development, the only times I've needed to use C was when I fell back to the older Carbon apis. Cocoa is all Objective C and quite different from old school c. As far as I know, all of the iPhone APIs use objective c and you would only ever need to use gangster style c if you're using a library already written with in it.

Upvotes: 0

Jeff Kelley
Jeff Kelley

Reputation: 19071

An interesting note is that Objective-C began its life as a sort of preprocessor to C. From /usr/include/objc/objc.h:

typedef struct objc_class *Class;
typedef struct objc_object {
    Class isa;
} *id;

Each Objective-C object can be described as a struct with a pointer to its class, its ivars, and function pointers for its methods. Message sending, etc. complicate things but when it comes down to it, everything could be done in C if you were patient enough.

Upvotes: 0

thyrgle
thyrgle

Reputation:

Objective-C is a strict superset of C. But, there are a lot of add ons in syntax that are overwhelming, in my opinion, and I can guarantee your going to use a lot of those additions to the C language because of Apple's frameworks. So if you were going to refresh your memory on C I would, personally, do something else.

As for an example:

All your programming is done, in the majority of case, in two classes. The AppDelegate or ViewController. Calling functions in C looks like:

foo();

But, because all this programming is done in classes you need to call it with an object:

FooViewController *FooCaller;
[FooCaller foo];

You use this syntax very often in iPhone programming, but the C syntax is not used often in iPhone programming.

Also, as for methodology, it is very different also because Objective-C is OO and C is procedural.

Upvotes: 1

user367836
user367836

Reputation: 91

Yes, Objective-C is a pure superset of C; it doesn't feel greatly like C, though. It's really more like java, +- some syntax changes, than traditional pointer-arithmetic-using systems-programming low-level C. The most obvious example being, for instance, that iPhone programming traditionally uses the NSString class to represent strings, rather than a C-style *char. You still can use *char to represent a string in Objective-C; it's just frowned upon and for practically everything you'll use it for (including, in all likelihood, 100% of all iPhone functionality) the NSString class is both cleaner and better-featured. That said, it'll get you back to the syntax pretty well, if not the idioms.

And yes, Objective-C is literally mandatory for iPhone dev. So yes, learning Objective-C is the way to accomplish both your goals.

Upvotes: 1

Yann Ramin
Yann Ramin

Reputation: 33167

Objective-C is a superset of C.

  1. Yes.
  2. Maybe. It is possible to use mostly objective C features without going back to regular C.

Upvotes: 0

Related Questions