0

A lot of Foundation objects provide two interfaces for creation:

  1. The general NSObject init method:

    _array = [[NSMutableArray alloc] init];

  2. A specialised factory method (convenience constructor), such as:

    _array = [NSMutableArray array];

I've recently developed a habit of doing the latter, and I was wondering if there was a reason to prefer one over the other.

I use ARC, so the autorelease nature of convenience constructors isn't a consideration per se.

sapi
  • 9,944
  • 8
  • 41
  • 71
  • If you use `ARC` then this answer pretty much covers you http://stackoverflow.com/questions/6776537/objective-c-with-arc-whats-better-alloc-or-autorelease-initializers – Alladinian Jun 13 '13 at 08:58
  • @Girish - I'll edit the question to reflect that I'm only interested in the differences under ARC – sapi Jun 13 '13 at 08:58
  • Those methods are called convenience constructors in Objective-C. – Nikolai Ruhe Jun 13 '13 at 08:58

1 Answers1

2

Convenience constructors are a little easier to use. They have the possible downside of an additional autorelease. ARC might optimize that away, though.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200