Get and set in Ios-day03_oc

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.