What is the correct way of init iVar variables in presence of ARC

后端 未结 2 1519
北荒
北荒 2021-01-03 16:31

Example iVar foo,

@property (nonatomic) NSString* foo; // inside .h

Option 1

@Synthesize foo;         


        
2条回答
  •  情话喂你
    2021-01-03 17:11

    I think you should understand the difference between these three and then decide which one is good for you.

    option 1: Here while initializing you are not using the synthesizer method. so there is no use of declaring property-synthesizer in .h and .m

    option 2: here you are using property-synthesizer. But the name of the method for accessing the instance and actual instance variable is same.

    option 3: Here again you are not using the property-synthesizer method. Here foo is the name of the method and _foo is the actual instance.

    In my opinion third one is the good. Since you the difference you can decide which one is good for you.

提交回复
热议问题