purpose of @property in objective c

后端 未结 3 1929
盖世英雄少女心
盖世英雄少女心 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

提交回复
热议问题