Now the most confusing thing for me with OC at the moment is the syntax. When you have an object you call its methods with the bracket syntax. For example...
OBJFoo* foo = [[OBJFoo alloc] init];
[foo sayHello];
[foo release];
The basic gist is [ ] in OC methods are called messages go figure damn IT types love their fancy words.
So lets say foo has a property call helloText. We can set this text using the set message and we can get the text using the get message.
OBJFoo* foo = [[OBJFoo alloc] init];
[foo setGreeting:@"Hello Foo"];
NSLog(@"%@", [foo greeting]);
[foo release];
With the new version of objective-c you can now use dot syntax to get at the accessor methods by saying foo.greeting = @"Hello Foo"; and foo.greeting to get the message.
This just adds to the confusion in my opinion. Just when I was understanding that everything in objective is pretty much a message and got use to reading the bracket syntax they throw this dot syntax at me. Yes I understand dot syntax but you can't use dot syntax for messages in general only accessors aka properties. So I have personally started converting all the code in the book to use brackets because for me it is easier to understand objective-c code with the brackets. Take this for instance...
Say we are using this window object inside of a class only so we prefix with self to make more sense.
NSWindow* myWindow = [[NSWindow alloc] init];
NSButton* myButton = [[NSButton alloc] init];
[[[self myWindow] contentView] addSubview:myButton]; // this is more understandable then
// this
[self.myWindow.contentView addSubview:myButton];
The reason I find it more readable is because
[[[self myWindow] contentView] addSubview:myButton] reads perfectly from left to right
get my instance of the myWindow object and then get its contentView now add the my button to our array of subviews.
the dot syntax
[self.myWindow.contentView addSubview:myButton];
is harder to understand what it is doing unless you 100% understand that the dot syntax is only used for properties and or instance variables.
yea the dot syntax makes the code look a bit cleaner but at the same time it is easy to glance at it and forget what is going on especially if you are not familiar with the underpinnings of objective-c. I think apple should have let this one out for consistencies sake.
Despite my syntax hiccups I am really starting to like the language overall as a whole. It is very well designed especially because of the amazing Cocoa framework.
I understand I did not go into detail on a lot of stuff because in all honesty I am just starting to get over the few hurdles the language throw's at me. But rest assured you will see more. My first project in the coming future is going to be a RSS reader. I understand that this is a game dev site but who cares it will be a interesting write up.
One thing I read recently that has softened my oppinion of Objective-C is that the direction it took off from C is inspired by smalltalk and also by lisp in some respects, which certainly helped me see their design decisions from the correct perspective. C++, instead, opted to go down the path of "logically extending" Vanilla C's syntax into an OO world, and so they ended up with a much different result. I certainly don't intend to write more of my software in Obj-C since anything I write for iOS/MacOS needs to have a core that's portable to at least windows, but this recent revalation will at least have me taking a little more joy in writing the parts that need to be done or interact with Objective-C (Cocoa/UI, etc).