Difference:
1>instancetype on a type representation, as with an ID, can represent any object type
2>instancetype can only be used on return value types and cannot be used as an ID on parameter types
One benefit of 3>instancetype than ID: The compiler detects the true type of instancetype
The 3rd explanation: in the following case///In the person.m file+ (ID) person{return [[Self alloc] init];}///MAINVIEWCONTROLLER.M, the following line of code, pointing to the object of the person class with a pointer to a string type, compiles through because the ID type returned by person, any pointer can point to itNSString *str = [person person];//If you use Instancetype, there will be a warning when compiling. That means Instancetype is more than an ID. Detect real-world functionality, exposing the risk of a program in advance+ (Instancetype) person{return [[Self alloc] init];} NSString *str = [person person];//There will be a warning, the person type returned by [person person], warning message: Assigning data of type person to string type //So to speak, wherever you can use the ID, it is recommended to change to instancetype, for example, the following code-(Instancetype) Initwithdic: (Nsdictionary *) app
{
if (self = = [Super init]) {
Self.name = app[@ "name"];
Self.icon = app[@ "icon"];
}
return self;
}
+ (Instancetype) Initwithdic: (Nsdictionary *) app
{
return [[[Self alloc]init] initwithdic:app];}
The difference between IOS Instancetype and ID