SAMWeak 0.0.1

SAMWeak 0.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Roman Kříž.



SAMWeak 0.0.1

  • By
  • Roman Kříž

Obj-C macro for easy creating weak references.

No more retain cycles within blocks.

Usage

There is only two macros, that creates another weak reference or strong reference.

  • 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
};

Example

 Simple weak reference:

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

Complex weak and strong referencing:

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