What is the difference between _name and self.name if name was a NSString

前端 未结 6 1073
无人及你
无人及你 2020-12-22 13:26

What is the defference if I called

NSString *theNameToDisplay = _name;

or

NSString *theNameToDisplay = self.name;
<         


        
6条回答
  •  别那么骄傲
    2020-12-22 13:47

    Before asking such question you had better read any objective c properties tutorial...try this http://www.raywenderlich.com/2712/using-properties-in-objective-c-tutorial or any other. If you created a property you must(ok, should) access an ivar through it so that setter method is called:

    - (void)setMyProp:(NSArray *)myProp {
       [myProp retain];
       [_myProp release];
       _myProp = myProp;
    }
    

提交回复
热议问题