In objective-C, how do I define a class? We can use the following format for representation:
@ Interface Class Name: parent class name {variable definition;} method definition; @ end;
An example is provided below:
@ Interface person: nsobject {nsstring * Name; int age;}-(nsstring *) Name;-(INT) age;-(void) setname: (nsstring *) input; -(void) setage: (INT) input; @ end;
The class definition starts with @ interface. It indicates the interface declaration of the class, and specifies the parent class of the class after the colon, @ end; indicates that the class definition ends.
In objective-C's class definition, the class variable definition is separated from the method definition. The variable definition is written in curly brackets, and the method definition of the class is written out of curly brackets. The method definition is unique. The specific format is as follows:
-(Void) setname: (nsstring) input;
Method Type return type method name method accept parameter type parameter name
The general format is as follows:
+/-(Return type) Sub-1 :( type 1) parameter 1 sub-2 :( type 2) parameter 2...
The method with a minus sign (-) is an instance method. You must use an instance of the class to call this method.
There is a plus sign, which indicates a static method of the class and can be called without instantiation.
Method definition of a parameter:
-(Void) setname: (nsstring *) input;
Method definition of the two parameters:
-(Void) setname: (nsstring *) Input andsecondname :( nsstring *) input1;