#import <Foundation/Foundation.h>
class declaration: Definition of Class name The first letter must be capitalized, if it is made up of multiple words using the Hump method: Example MyBlog
@interface person:nsobject{
The definition of a class property: The attribute name is preceded by an underscore: example _age
@public
int _age;
float _height;
}
Definition of a class method
-(void) eat;
@end
Implementation of the class
@implementation person
Implementing a class method
-(void) eat{
NSLog (@ "age =%d, height =%.2f people eating", _age, _height);
}
@end
int main (int argc, const char * argv[]) {
Person *p = [[Person alloc] init];
Assigning a value to a class's properties
P->_age = 20;
P->_height = 170;
Calling class methods
[P eat];
Output Age and Height
NSLog (@ "age =%d, height =%.2f", P->_age, P->_height);
return 0;
}
OC--declaration and definition of simple class