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?
There are a bunch of reasons here: http://macresearch.org/difference-between-alloc-init-and-new
Some selected ones are:
new
doesn't support custom initializers (like initWithString
)alloc-init
is more explicit than new
General opinion seems to be that you should use whatever you're comfortable with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With