From what I understand, instancetype declares to the compiler that the return type of the method is the same as the class receiving the message.
Traditionally I've always declared my singleton initializers with the class name explicitly set as the return type:
@interface MyClass : NSObject
+ (MyClass *)sharedInstance;
@end
Now I'm wondering if I should use instancetype instead, like so:
@interface MyClass : NSObject
+ (instancetype)sharedInstance;
@end
In the end the result is the same, I'm just wondering if there's a reason to use one or the other here?
id
, withinstancetype
, we ensure that the compiler is checking type so we gain flexibility without being ambiguous. – Vitalism