Thursday, February 8, 2007

Using Objects in Objective-C

As you know, the mac programming language, Objective-C, handles things differently than C# for windows or Java. It took me a little time to understand how all this really works. Here is the syntax for using objects.

When you declare a object, you will need to use this following pattern:

NameOfObject *objectTitle;
- The * tells the compiler that you are creating a variable and not using one.

Accessing an object is differently than other languages too.
When you access an object, it is this following pattern:

[objectTitle methodName];
[objectTitle propertyName];

This essentially replaces the C# way of doing things, which is:

Now when you declare something that is native to Objective-C's mother language C then you don't need the *.

For example:
double objectTitle;

Putting the * before the objectTitle will cause the compiler to freak out. It took me a couple of days to get this straight. Every time I used a double, I would do the * and wonder why it didn't work.

Hope this helps out the New-To-Mac Programmer's.

No comments: