The evolution of a class method for quickly creating objects:
Original version:
+ (Book *) book {
return [[[Book Alloc] init] autorelease];
}Evolutionary version:
+ (ID) book {
return [[[Self alloc] init] autorelease];
}Evolution version Two:
+ (instancetype) book {
return [[[Self alloc] init] autorelease];
The evolutionary version is better than the original version, it is in the subclass of the method of the parent class, the return is the subclass itself, not the original version of the parent class case: There is Dic.h this class, inherited from the book class, and this class has-(void) Findword;dic *xinhuadic = [dic book]; // When you execute this method, you will find the book method in the DiC class and find it in the parent class .[Xinhuadic Findword];//execution to this line of the program will crash, reported "classic error"So withSelf and IDThanFixed TypeWell. Self is characterized by who calls this method, self represents who evolves two version better than the one version of evolution see another essay <instancetype and ID differences >
Self in the class method of the IOS Quick Create object