Want to learn Objective-C but syntax is very confusing

Posted by Sahat on Stack Overflow See other posts from Stack Overflow or by Sahat
Published on 2010-06-10T00:52:20Z Indexed on 2010/06/10 1:12 UTC
Read the original article Hit count: 446

Coming from Java background I am guessing this is expected. I would really love to learn Objective-C and start developing Mac apps, but the syntax is just killing me.

For example:

-(void) setNumerator: (int) n
{
    numerator = n;
}

What is that dash for and why is followed by void in parenthesis? I've never seen void in parenthesis in C/C++, Java or C#. Why don't we have a semicolon after (int) n? But we do have it here:

-(void) setNumerator: (int) n;

And what's with this alloc, init, release process?

myFraction = [Fraction alloc]; 
myFraction = [myFraction init];
[myFraction release];

And why is it [myFraction release]; and not myFraction = [myFraction release]; ?

And lastly what's with the @ signs and what's this implementation equivalent in Java?

@implementation Fraction

@end

I am currently reading Programming in Objective C 2.0 and it's just so frustrating learning this new syntax for someone in Java background.

© Stack Overflow or respective owner

Related posts about java

Related posts about objective-c