objective-coop

Use of alloc init instead of new


Learning Objective-C and reading sample code, I notice that objects are usually created using this method:

SomeObject *myObject = [[SomeObject alloc] init];

instead of:

SomeObject *myObject = [SomeObject new];

Is there a reason for this, as I have read that they are equivalent?


Solution

  • There are a bunch of reasons here: http://macresearch.org/difference-between-alloc-init-and-new

    Some selected ones are:

    General opinion seems to be that you should use whatever you're comfortable with.