05-Class--+-number use

Source: Internet
Author: User

#import <foundation/foundation.h>/* Object Method 1> minus-the beginning 2> can only be called by the object to invoke the member variable (instance variable) of the current object in the 3> object method 1> Plus + begins 2& Gt Can only be called by the class (name) in the 3> class method can not access the benefits of the member variable (instance variable) class method and the use of the application 1> not depend on the object, the execution efficiency is high 2> can use class method, try to use class method 3> occasion: When the method inside does not need to use the member variable, You can change the class method to allow the same name as the class method and the object method */@interface person:nsobject{int age;} Class methods are preceded by + (void) printclassname;-(void) test;+ (void) test; @end @implementation person+ (void) printclassname{//Erro R:instance variable ' age ' accessed in class method//Instance variable "The class cannot access the//nslog (@" This class is called person-%d ")       -(void) test{NSLog (@ "111-%d", age); [Person test];}       + (void) test{//will cause a dead loop//[person test];       NSLog (@ "333"); Will cause a dead loop///[person test];}       @endint Main () {//[person printclassname];       [Person Test];    Person *p = [person new];       [P test]; /*-[person Printclassname]: Unrecognized selector sent to instance 0x7fa520c0b370////The system will assume that the Printclassna is now called       Me is an object method//[p Printclassname]; return 0;}

  

05-Class--+-number use

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.