iOS development and the like and objects
OC and Java are a kind of object-oriented language, starting today I and everyone together to learn this object-oriented language OC, welcome you what problems with me to explore and learn.
The OC definition class has two steps: 1, the interface section (popularly speaking is. h file) 2, the implementation of the section (popularly speaking is. m file)
The interface section syntax is as follows:
#interface: Myclass:nsobject
{
int _count;
nsstring* _name;
-(ID) initwithstring: (nsstring*) Name;
+ (myclass*) creatmyclasswithstring: (nsstring*) Name;
}
@ end
Note: Class name: Myclass
Parent class: NSObject
Member variable declaration: int M_count;
nsstring* M_name;
Method declaration: -(ID) initwithstring: (nsstring*) Name;
+ (myclass*) creatmyclasswithstring: (nsstring*) Name;
The definition member variable is formatted as follows:
Type: Can be any of the basic data types allowed by the OC language, and can include basic types, constructed types, and various pointer types
Member variable: As long as it is a valid identifier, it is recommended that the OC member variable begin with (_) from Xcode4.
The method declaration is described as follows:
-(void) InsertObject: (ID) anobject atindex: (nsuinteger) index
Note: Method type identification:-
The method type identifies only + and-two + means that the method is a class method called directly with the class name-representing that the method is an instance method that must be used by an object to invoke
Implementation Section :
@implementation Myclass
{
int _count;
nsstring* _name; Member variables
}
-(ID) initwithstring: (nsstring*) Name
{
Define method body
}
+ (myclass*) creatmyclasswithstring: (nsstring*) Name
{
Define method body
}
iOS development and the like and objects