Get and set in OC are essentially the same as in C#/java
It's just a different form of expression.
As follows:
1 @interface Car:nsobject 2 3 int wheels; 4 5 6 -(void 7 -(void ) Setwheels: (int ) Newwheels; 8 -(int ) Wheels; 9 @end
Realize:
1 @implementationCar2 3-(void) run{4NSLog (@"%i A wheel of a car running up.", wheels);5 }6-(void) Setwheels: (int) newwheels{7 if(Newwheels <=0) {8Newwheels =4;9 }TenWheels =Newwheels; One } A-(int) wheels{ - returnWheels; - } the @end
Naming conventions:
The set method, as the name implies, is the method of setting the value, in OC generally start with set, the first letter of the variable capitalization, the purpose is to play a certain limit, if the value set is not reasonable, we can judge in the method, avoid direct access to its variables
The Get method is a method of taking a value, which is generally consistent with the variable name in OC (I prefer get to start)
Get and set in Ios-day03_oc