Created
March 14, 2013 23:27
-
-
Save AtomicCat/5166194 to your computer and use it in GitHub Desktop.
Ugly way to call super from a weak self
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <Foundation/Foundation.h> | |
| #import <objc/objc-runtime.h> | |
| @interface Foo : NSObject | |
| @end | |
| @implementation Foo | |
| - (NSString*)description | |
| { | |
| __weak id weakself = self; | |
| Class class = class_getSuperclass([weakself class]); | |
| struct objc_super weakSuper = { weakself, class }; | |
| NSString *string = objc_msgSendSuper(&weakSuper, @selector(description)); | |
| return string; | |
| } | |
| @end | |
| int main(int argc, const char * argv[]) | |
| { | |
| @autoreleasepool { | |
| Foo *foo = [[Foo alloc] init]; | |
| NSLog(@"%@", foo); | |
| } | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment