Create a class file for the. h file interface (Create a Class)
@interface myclass:nsobject{
Class Variable declaration
int A;
int b;
}
Class Property declaration
(int) P2
class method declaration
-(return_type) Method_one;
-(Return_type) Method_two: (int) P1;
Static methods
+ (void) SayHello;
@end
Execute file. m file
@implementation MyClass {
int C;
}
class method Definition:
-(Return_type) method_one{
//
}
The implementation of static methods, without the need for strength can be called
+ (void) sayhello{
NSLog (@ "Hello");
}
@end
Use static: [MyClass SayHello];
Use the strength approach
Mynew=[myclass New]
[Mynew Method_one]
The difference: the. h file represents a header file that declares the member variables and methods and attributes in various classes, and so on import with a header file
. m files are primarily used to implement the methods stated in the. h file.
Ep:
In the. h file, declare a method:
-(void) MyMethod;
Implemented in. m files
-(void) mymethod{
NSLog (@ "This is my new method");
}
A method with parameters
-(void) setcolortored: (float) Red green: (float) Green Blue: (float) blue{
}
Call
[MYOBJ setcolortored:1.0 green:0.8 blue:0.2]
2: Class
Interfaces and implementations
OC class is divided into interface definition and implementation of two parts, interface (interface) definition placed in the header file, extension name is. h
Implementation (Implementation) put in the implementation file the extension is the. m file here Note that the interface and implementation are one by one corresponding
3:import header File
#import "xxx.h" Reference Library
#import "<React/reactxxx.h>" referencing the framework framework
4oc+ Frame Cocoatouch+ide
Reference article: http://www.cnblogs.com/wellsoho/p/4313312.html
iOS Learning Note One