OC High Efficiency 52 multi-use type constants, less # define preprocessing directives

Source: Internet
Author: User

  viewcontroller.m//  oc High Efficiency 52 for multiple use type constants, less # define preprocessing directives/** *      1.  do not define constants with preprocessing. The defined constants do not contain type information, and the compiler simply performs a find-and-replace operation on this basis before compiling. Immediately someone redefined the constant value, and the compiler does not produce a warning message, which causes the constant values in the application to be inconsistent.        2. Use static const  in the implementation file to define constants that are visible only within the compilation unit. Because such constants are not in the global symbol table, you do not need to prefix their names.        3. use extern in the header file to declare the global variable and define its value in the relevant implementation file. This constant is to appear in the global symbol list, so its name should be separated, usually prefixed with the class name associated with it.  */#import   "ViewController.h" #define  animation_durtion 0.3 //defined constants, no type information static  const nstimeinterval kanimationduration = 2.0;//know that constant types help write development documents//variables must be used static  const  to declare that if the view modifies the variable declared by the const, the compiler will error @interface viewcontroller  () @endNSString  *const  eocloginmanagerdidloginnotificaton = @ "Eocloginmanagerdidloginnotificaton"; @implementation   viewcontroller-(void) animate{    [uiview animatewithduration:kanimationduration  Animations:^{        //perform animations;         uiview *view = [[uiview alloc]initwithframe:cgrectmake (100, 100,  80, 80)];        view.backgroundcolor = [uicolor  orangeColor];        [self.view addSubview:view];     } completion:^ (bool finished)  {             }];} -  (void) viewdidload {    [super viewdidload];    //  Do any additional setup after loading the view, typically  from a nib.    [self animate];//    [self login];     uibutton *btn = [[uibutton alloc]initwithframe:cgrectmake (150, 300, 100, 30)];    btn.backgroundcolor = [uicolor  Greencolor];    [btn addtarget:self action: @selector (login)   forcontrolevents:uicontroleventtouchdraginside];    [btn settitle:@ "Click Notifications"   FORSTATE:UICONTROLSTATENORMAL];    [SELF.VIEW ADDSUBVIEW:BTN];} -(void) Login{    [[nsnotificationcenter defaultcenter]postnotificationname: eocloginmanagerdidloginnotificaton object:nil];    }-  (void) didreceivememorywarning {    [super didreceivememorywarning];     // dispose of any resources that can be recreated.} @end


OC High Efficiency 52 multi-use type constants, less # define preprocessing directives

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.