What is the underlying mechanism for ivar synthesis in the modern Objective C runtime

前端 未结 3 1833
时光说笑
时光说笑 2020-12-13 20:35

One of the features of the modern (64 bit OS X and iPhone OS) Objective C runtime is the ability for properties to dynamically synthesize ivars without explicitly declaring

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 21:14

    What you are looking for is @synthesized name, like:

    @synthesize name = _name;
    
    ...
    
    - (NSString *) name {
        if (!name) {
            _name = @"Louis";
        }
    
        return _name;
    }
    

提交回复
热议问题