Thursday, February 21, 2013

Hello World - objective-C style


Superset of C (C + Smalltalk) = Objective-C

It comes as quite a surprise when you learn that Objective-C is pretty old. It is from the days of C. At the time C++ was emerging Objective-C also paved a way for itself.

What do you mean by superset?
It is basically C with new functionalities added to it.

I tried my hand on writing the very first objective-c code. Obviously it had to be "Hello World" program. This has been simplified by objective-C. As you make a new project it by default is Hello World. You don't even have to type in the words.

Looking at the code you will notice certain things.
First of all the "main" function is from the good, old C language.

int main(int argc, char *argv[])

I will not go into this as it is used for passing inline parameters to the main function.

So when you look at the code how do tell if a piece of code is from C or from Objective-C.
There are few things if you notice, such as square brackets [], @ symbol and "NS". These indicate the parts that were added to C to make it Objective-C.

No comments:

Post a Comment