basic concept: In O-c, after the class is created, you also need to add properties and methods to a class, and the previously mentioned set and get methods are cumbersome, so the @property compiler directive is introduced. @property is a compiler directive. the so-called compiler directive tells the compiler what to do with the content and what to do. @property tells the compiler to declare the reader (getter method and setter method)
1. in today's Xcode, @property can generate instance variables, declaration of methods, and implementation of methods at the same time.
2, rewrite Getter Method and Setter Method
Although @property is convenient, there will always be a day when the auto-generated method does not meet your needs. Therefore, you can override the Getter method or setter method, which satisfies the need for use.
Instead of overriding the parent-class method in the inheritance, the override here implements the setter method or getter method that you need, so that the system does not automatically generate it, and it does not write the method itself or is generated by the compiler. But you can't implement two methods at the same time.
As an example, you can use @property to replace the commented out part:
#import <Foundation/Foundation.h>
@interface Employee: NSObject
//(1) the name, age, and wage attributes in the class are used separately Char Array, int Variables and Double variable storage.
{
NSString * _NAME;
//
int _age;
//
Double _salary;
//
}
// Easy to use @property , replacing Set and the Get
@property nsstring * name;
@property int * age;
@property Double salary;
-(void) Mythod;
//// Design Show method.
-(void) show;
//// encapsulating three method sets
-(void) SetName: (NSString *) name;
-(void) Setage: (int) age;
-(void) Setsalary: (double) salary;
////getter Method
//
-(NSString *) name;
-(int) age;
-(double) salary;
@end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
O-c related-[email protected] keywords Introduction and use