
An introduction to Objective-C - fogus
http://thinkvitamin.com/code/ios/an-introduction-to-objective-c/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+vitaminmasterfeed+%28Think+Vitamin%29&utm_content=Google+Reader
======
adamjernst
This tutorial is riddled with dangerous errors even though it's pretty basic.
To start with, here's his initializer:

    
    
      - (id) initWithTitle: (NSString *)aTitle{
        self = [super init];
        if (self) {
          title = aTitle;
        }
        return self;
      }
    

aTitle isn't retained (and no, he's not using ARC). This is such an obvious,
basic mistake that I have no faith in the author at this point.

Here's another error:

    
    
      For example, this is valid code:
      NSObject obj = [Book createBookWithTitle:@"A Brave New World"];
    

That's not true. It's missing the pointer (NSObject *, not NSObject).
Furthermore it's otherwise syntactically valid but comes dangerously close to
violating Cocoa best practices for memory management. The method (which
returns an autoreleased result in their examples) should be named
"bookWithTitle:".

Putting "create" in the name doesn't actually violate the memory management
rules (in Cocoa, only methods that have alloc, new, copy, or mutableCopy
return owning references). But it will cause confusion with the Create Rule
from Core Foundation:

    
    
      Object-creation functions [have] “Create” embedded in the name...
      it is your responsibility to relinquish ownership (using CFRelease) when you have finished with it
    

Sure, Core Foundation is not Cocoa. But since it's often intermixed, sometimes
explicitly with toll-free bridging, boy are people going to be confused
someday!

~~~
natesm
Heh, as a person that loves Cocoa but doesn't own an iOS device (ok, I do have
an iPod touch I got for free with my MBP), initializers like that are _all
over_ my code.

~~~
Greenisus
initializers should look like that. the problem is this:

title = aTitle;

he should say self.title instead to avoid memory issues.

~~~
natesm
Oh, what I meant is that on the Mac we can use garbage collection, so it's not
always a problem.

I don't really like the property dot syntax though, I always use the
`setProperty:` form for consistency (is it a struct or an object? why is the =
operator sending an Obj-C message?)

------
flyosity
I wrote a longer Obj-C & Cocoa getting started guide (about 30 pages) that's
free and available here if anyone is interested:
<http://designthencode.com/scratch/>

~~~
joelhooks
wow Mike, very nice. Cheers.

------
js2
Please, start with Scott Stevenson's tutorials instead:

<http://cocoadevcentral.com/>

------
lfx
First two images with basic explanations what is what is most valuable for
beginner.

