SAMWeak 0.0.1

SAMWeak 0.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2014年12月

Roman Kříž维护。



SAMWeak 0.0.1

  • 作者
  • Roman Kříž

Objective C宏,用于轻松创建弱引用。

不再在代码块中存在retain循环。

使用方法

只有两个宏,分别创建另一个弱引用或强引用。

  • WEAK(__self)
  • STRONG(__self)
WEAK(self);
void (^ block)() = ^{
    // now you can use _self variable as weak reference
};
WEAK(self);
void (^ block)() = ^{
    STRONG(_self);
    // now you can use s_self variable as strong reference that is created from weak reference
};

示例

简单的弱引用

WEAK(self);
[UIView animateWithDuration:0.25 animations:^{
        _self.frame = CGRectMake(0.0f, 0.0f, 10.0f, 10.0f);
}];

复杂的弱引用和强引用

WEAK(self);
[UIView animateWithDuration:0.25 animations:^{
        STRONG(_self);
        s_self->variable = 0;
}];