objective-c - How to assign values ​​to member variables
怪我咯
怪我咯 2017-05-02 09:27:14
0
2
576

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?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
左手右手慢动作
@implementation ViewController

{
    UIView *_iconView;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    NSLog(@"%@", self->_iconView);
    NSLog(@"%@", _iconView);
}
过去多啦不再A梦

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template