Guest User

Untitled

a guest
Oct 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. //
  2. // imp.m
  3. // imp
  4. //
  5. // Copyright (c) 2012 Matt Rajca. All rights reserved.
  6. //
  7.  
  8. #import <Foundation/Foundation.h>
  9. #import <objc/runtime.h>
  10.  
  11. @interface Person : NSObject
  12.  
  13. - (void)sayHello;
  14.  
  15. @end
  16.  
  17.  
  18. @implementation Person
  19.  
  20. - (void)sayHello {
  21. NSLog(@"hello");
  22. }
  23.  
  24. @end
  25.  
  26.  
  27. int main(int argc, const char *argv[])
  28. {
  29. @autoreleasepool {
  30. Person *person = [[Person alloc] init];
  31. [person sayHello];
  32.  
  33. IMP a = imp_implementationWithBlock(^{
  34. NSLog(@"hello again");
  35. });
  36.  
  37. class_replaceMethod([Person class], @selector(sayHello), a, NULL);
  38.  
  39. [person sayHello];
  40. }
  41.  
  42. return 0;
  43. }
Add Comment
Please, Sign In to add comment