Permalink
Browse files

Adding snippet for __weak self reference (thanks @jasongregori)

  • Loading branch information...
1 parent 7895c51 commit 3ab388dcb51223caefe20385b293d395c2852d4f @mattt mattt committed May 29, 2012
Showing with 8 additions and 0 deletions.
  1. +8 −0 weakself.m
View
@@ -0,0 +1,8 @@
+// __weak self
+// Declare weak referece to self
+//
+// Platform: All
+// Language: Objective-C
+// Completion Scope: Function or Method
+
+__weak __typeof(&*self)weakSelf = self;

3 comments on commit 3ab388d

@jasongregori

I don't know why I just now saw this but, nice!

@JmeHsieh

May I ask why not just
__weak __typeof(self)weakself = self;

What's the difference by adding "&*" before self in __typeof?

@jasongregori

That didn't work before. According to this stack overflow post this was fixed in Xcode 4.4: http://stackoverflow.com/a/11226768/184561. So this should be updated.

Please sign in to comment.