The instancetype return type
suggest changeObjective-C has a special type called instancetype that can only be used as a method’s return type. It means “instance of the receiver’s class.”
Consider the following class hierarchy:
@interface Foo : NSObject
- (instancetype)initWithString:(NSString *)string;
@end
@interface Bar : Foo
@end
When [[Foo alloc] initWithString:@"abc"] is called, the compiler can infer that the return type is Foo *. Bar derives from Foo and does not override the initializer. Because of instancetype, the compiler can infer that [[Bar alloc] initWithString:@"xyz"] returns Bar *.
If -[Foo initWithString:] returned Foo * instead, [[Bar alloc] initWithString:] would be inferred to return Foo *, not Bar *. instancetype fixes that.
Before instancetype, initializers, class methods such as singleton accessors, and other methods that return an instance of the receiver’s class returned id. id means “an object of any type,” so the compiler cannot warn that NSString *wrong = [[Foo alloc] initWithString:@"abc"]; assigns to the wrong type.
Due to this issue, initializers should always use instancetype instead of id as the return value.