Skip to content

Instantly share code, notes, and snippets.

@karajanyp
Forked from markd2/imp.m
Created April 11, 2018 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karajanyp/96d9c7e511d52d4db73473201ae7fe12 to your computer and use it in GitHub Desktop.
Save karajanyp/96d9c7e511d52d4db73473201ae7fe12 to your computer and use it in GitHub Desktop.
Jump through an IMP
#import <Foundation/Foundation.h>
// Call a method through a cached IMP pointer.
// clang -g -Wall -framework Foundation -o imp imp.m
id (*uppercase)(id, SEL, ...);
int main (void) {
@autoreleasepool {
NSString *string = @"Bork";
uppercase = [string methodForSelector: @selector(uppercaseString)];
NSString *upcase = uppercase (string, @selector(flonknozzle));
NSLog (@"%@ -> %@", string, upcase);
}
return 0;
} // main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment