Skip to content

Instantly share code, notes, and snippets.

@atomkirk
Last active December 17, 2015 10:29
Show Gist options
  • Save atomkirk/5595593 to your computer and use it in GitHub Desktop.
Save atomkirk/5595593 to your computer and use it in GitHub Desktop.
weak self

There really needs to be an easier way to do this built into the language, but until then, I use my handy CodeBox app to paste in this whenever I need a weak reference to self:

__weak typeof(self) celf = self;
[self block:^{
  celf.foo = bar;
}];

It's a nifty trick, but Apple, please... I shouldn't have to declare a weak self, I should be able to use self with a predefined symbol for "self" that the compiler will then write the weak self declaration for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment