creat by Guo Chai March 30, 2015 16:33:12
Specifies that the initialization method is an overload of the Init method implementation of the parent class, and it is not necessary to declare it in the. m file, which is called by other methods in this class.
Implementation of the method:
-(Instancetype) init
{
if (self = [super init])///can also self = [self init] to be called by other methods (init methods) in this class. Here self executes the pair//image of the method
{
Variable initialization in this class
}
return self;
}
=========================================================================================
Convenience constructor: Is a class method that encapsulates the Alloc and Init methods, which is more convenient to use.
For example:
+ (ID) Vnherowithblood: (int) blood
{
Vnhero *hero = [[Vnhero alloc] init];
[Hero setvnheroblood:blood];//called Setter method
return hero; This is not the self of the past.
}
Main function declaration:
Invoke Convenience Builder
Vnhero * vn = [Vnhero vnherowithblood:67];
NSLog (@ "blood =%i", [vn blood]);
========================================================================================
OBJECTC----convenience constructors and specifying initialization