Skip to content

Instantly share code, notes, and snippets.

@Alos
Created July 25, 2010 03:02
Show Gist options
  • Save Alos/489252 to your computer and use it in GitHub Desktop.
Save Alos/489252 to your computer and use it in GitHub Desktop.
//
// iDrawAppDelegate.m
// iDraw
//
// Created by Alos on 7/22/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "iDrawAppDelegate.h"
#import "MyViewController.h"
#include <objc/runtime.h>
@implementation iDrawAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
void drawWithRedInk(id self, SEL _cmd, NSRect *rect){
NSLog(@"Using red ink");
[[NSColor redColor] set];
[[self valueForKey:@"path"] stroke];
}
-(IBAction)loadDynamicCode: (id) sender{
NSLog(@"Adding new code!!!");
Method newMethod = class_getInstanceMethod([iDrawAppDelegate class], @selector(drawWithRedInk));
class_replaceMethod([MyViewController class], @selector(drawRect:), (IMP)drawWithRedInk, method_getTypeEncoding(newMethod));
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment