purpose of @property in objective c

后端 未结 3 1903
盖世英雄少女心
盖世英雄少女心 2021-01-28 20:09

Look a the below code;

@interface testViewController : UIViewController
{
     int age;
     UIPopoverController *popoverController;
}
@property (nonatomic , ret         


        
相关标签:
3条回答
  • 2021-01-28 20:39

    It is difficult to advise anything better then official documentation (at least you should start with reading it).

    @property (nonatomic , retain ) int age;
    

    Is really supposed to declare setter/getter methods for age ivar, but that line will give compiler error as you can't declare property with retain attribute for non-object types (see docs for more details)

    @property (nonatomic , retain ) UIPopoverController *popoverController;
    

    This line does not differ much from the 1st one - it also declares setter and getter methods for popoverController ivar, and automatically synthesized setter will retain popoverController it gets

    0 讨论(0)
  • 2021-01-28 20:51

    @synthesize always creates the accessors. In your case:

    - (void) setPopoverController:(UIPopoverController *)value;
    - (UIPopoverController *) popoverController;
    
    0 讨论(0)
  • 2021-01-28 20:54

    If you have this:

    @property (nonatomic , retain ) UIPopoverController *popoverController;
    

    the methods generated by @synthesize will be something like:

    -(UIPopoverController*) popoverController
    {
        return popoverController;
    }
    
    -(void) setPopoverController: (UIPopoverController*) newValue
    {
        [newValue retain];
        [popoverController release];
        popoverController = newValue;
    }
    
    0 讨论(0)
提交回复
热议问题