(id)
tells the compiler to expect any kind of object. This makes sense for a method where you honestly have no idea what will come back, for example NSArray
's -(id)objectAtIndex:
. However, in an init
method you know what will be returned: an instance of the object's class or a subclass thereof. For example, [[NSArray alloc] init]
will never return a UIButton
.
By providing instancetype
instead of id
you tell the compiler what kind of object to expect. This means the compiler can help you prevent errors.
See this link: http://nshipster.com/instancetype/. It will tell you all you need to know.