Finally, we can now get onto the reason I created this blog! Learning Objective-C!

I’m doing some online tutorials to get the basics right. Since I’m coming from a C and C++  background, I was expecting a lot of similarities. However, there seems to be some fundamentals differences in syntax.

For example, lets take Hello World in a few languages:

printf(“Hello World”);  // C

cout << “Hello World”; // C++

NSLog(@”Hello World”); // Objective-C

First thing,  why the hell is there an @ symbol there??? Secondly,what the hell is NSLog???

Well, the @ symbol is there to tell Objective-C to expect a string. Thats just how it works.

Secondly, NSLog comes from back in the 80’s before Steve Jobs took over Apple. He was working on the NextStep language (NextStep => NS, see?) so when he did become boss in Apple, he rather biasedly (is that a word???) used the NextStep platform to build Mac OSX. So even though its evolved to use Objective-C, they still use the foundation classes from NextStep. FYI, don’t mind the capitalisation of NextStep. It can be written as any of NeXTSTEP, NeXTstep, NeXTStep, or NEXTSTEP.

So anyway, from my first lesson in Objective-C, I have spotted another oddity. This time to do with calling methods in classes. See below:

myClass.doFunction(); // C++

myClass.doFunction(myValue); // C++

[myClass doFunction]; // Objective-C

[myClass doFuction:myValue]; // Objective-C

Thats for calling methods with zero or one parameters. I’m currently trying to get my head around sending 2 parameters in Objective-C! I need to find some example code….