-1

How come Apple changed the built-in init method snippet from:

- (id)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

to:

- (instancetype)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

?

enter image description here

Mikael
  • 3,572
  • 1
  • 30
  • 43
  • Are you asking what `instancetype` is or are you asking why the snippet was changed? – David Rönnqvist Mar 19 '14 at 09:14
  • @DavidRönnqvist actually both. There must be a reason why Apple wants developers to use intancetype instead. – Mikael Mar 19 '14 at 09:16
  • 1
    take a look at [this thread](http://stackoverflow.com/questions/8972221/would-it-be-beneficial-to-begin-using-instancetype-instead-of-id) for a decent explanation – Fonix Mar 19 '14 at 09:18
  • 1
    Where did you see that snippet? Because I believe `instancetype` is intended for class constructor methods. – Merlevede Mar 19 '14 at 09:19
  • @Merlevede updated my question. Just start type init and then select "init - Objective-C -init Method" – Mikael Mar 19 '14 at 09:21
  • I avoid the issue by never using snippets. They take too much time. – trojanfoe Mar 19 '14 at 09:25

1 Answers1

2

instancetype is the best return type for Objective-C init methods. If you write id instead of instancetype in an init method then the compiler will assume you really meant instancetype (at least in ARC mode).

Greg Parker
  • 7,972
  • 2
  • 24
  • 21