First, @property
Using @property-Modified variables, the compiler automatically generates an underlined property with the same name and a corresponding get set method. Pass. The way Access property is actually access to the corresponding get set method, so in get set can not use self. The form of the property, otherwise you will fall into a dead loop. When simultaneously overriding two methods is required in the implementation file to add @syntheSize property = _property;
In a class, you can directly access its corresponding property.
A.h@property (nonautomic,copy) nsstring *a;//a.m@synthesize a = _a; -(void) SetA (NSString *val) { _a = [NSString stringWithFormat: @ "%@123", Val]; } -(NSString *) a{ return _a; }
In OC, only the attributes declared in the. h can be accessed externally, and the same modifier in Swift controls the access level of the member variable.
In Swift, the attributes are divided into the store and computed property, with a set get willset didset four methods.
The Store property uses the default Get set method, and once the Get or set method is overridden, it is determined that the variable must be a computed property.
Didset and Willset can only be used to store properties.
As with OC, use self in get . gets the property value or use self in set, Willset, Didset . setting the value of a property causes an infinite loop to crash.
OC, Swift property, member variable