To set the initialization method of a variable pass parameter
-(Instancetype) Initwithhour: (int) H and Minute: (int) m and second: (int) s;
And then in the implementation section
-(Instancetype) Initwithhour: (int) H and Minute: (int) m and second: (int) s;
{
Self=[super Init];
if (self!) =nil) {
Hour=h;
Minute=m;
Second=s;
}
}
Then the main function below is directly assigned
Time*tm2=[[time alloc]initwithhour:13 and minute:30 and second:0];
Background Direct Display 13:30:00
Overriding Init only needs to be written in the implementation section directly and does not need to be re-declared in the declared. h file
Init is a method of NSObject
For classes that inherit from NSObject
The element that initializes the element subclass of the parent class when space is opened for memory needs to be reinitialized initialized as follows
Initialize the part of the parent class first
self=[Super Init];
Then initialize your own part first to determine if self is nil nil stating that the parent class failed to initialize
-(ID) init//id is a type that points to any "object" or can be filled in instancetype he only uses it in the initialization.
{
if (Self=[super init]) {//super is part of the initialization parent class if the parent class fails to initialize then self is nil
{
m_m=10;
m_s=10;
m_h=20;
}
return self;
}
}
}
}
Initialization of the parent class and subclass of Init