We all know that the assignment of attributes is to call the setter method of the attribute, but how are member variables assigned? What is its internal implementation principle?
ringa_lee2017-05-02 09:29:14
@implementation ViewController
{
UIView *_iconView;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%@", self->_iconView);
NSLog(@"%@", _iconView);
}
过去多啦不再A梦2017-05-02 09:29:14
I think I want to ask about the difference between ivar and property.
property = ivar+getter+setter
For example
property (assign) int a will generate a member variable of _a by default, which we call ivar
At the same time, a setter method will be generated, which looks like this:
-(void)setA:(int)a {
_a = a;
}
A getter method will also be generated, which looks like this:
-(int)a {
return _a;
}
At the same time, it will give _a some gain buffs, such as strong strong reference and weak weak reference to control the life cycle of this variable.
So property is just a form of programming, you don’t need to pay too much attention to it, you can completely follow your own routine.