美文网首页
高性能iOS应用开发 笔记03

高性能iOS应用开发 笔记03

作者: 梓华 | 来源:发表于2017-11-26 23:32 被阅读5次

    变量限定符

    _strong
    _weak 会被置nil
    __unsafe_unretained 不会被置为nil
    _autoreleasing

    Person * _strong p1 = [[Person alloc] init];
    Person * _weak p2 = [[Person alloc] init];
    Person * __unsafe_unretained p3 = [[Person alloc] init];
    Person * _autoreleasing p4 = [[Person alloc] init];
    

    属性限定符

    strong _strong
    weak _weak
    assign __unsafe_unretained
    copy _strong
    retain _strong
    unsafe_unretained __unsafe_unretained

    @property (nonatomic, strong) UILabel *lab;
    @property (nonatomic, weak) id<UIApplicationDelegate> delegate;
    @property (nonatomic, assign) NSInteger row;
    @property (nonatomic, assign) BOOL flag;
    @property (nonatomic, copy) NSString *name;
    @property (nonatomic, retain) Person *person;
    @property (nonatomic, unsafe_unretained) UIView *view;
    

    Demo

    - (IBAction)createStrongPhoto:(id)sender
    {
        HPPhoto * __strong photo = [[HPPhoto alloc] init];
    }
    

    函数结束了 才会销毁

    - (IBAction)createWeakPhoto:(id)sender
    {
        HPPhoto * __weak wphoto = [[HPPhoto alloc] init];
    }
    

    对象立即被回收

    - (void)createStrongToWeakPhoto:(id)sender
    {
        HPPhoto * sphoto = [[HPPhoto alloc] init];
        HPPhoto * __weak wphoto = sphoto;
    }
    

    函数结束了 才会销毁

    - (void)createUnsafeUnretainedPhoto:(id)sender
    {
        HPPhoto * __unsafe_unretained wphoto = [[HPPhoto alloc] init];
    }
    

    对象会立即被释放

    相关文章

      网友评论

          本文标题:高性能iOS应用开发 笔记03

          本文链接:https://www.haomeiwen.com/subject/yidlbxtx.html