groby / iCalFix

Fixes various annoyances with iCal

This URL has Read+Write access

iCalFix / MethodSwizzle.m
100644 37 lines (25 sloc) 0.835 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <objc/objc-class.h>
 
#include "MethodSwizzle.h"
 
/**
* Swizzle to selectors on a class
*/
void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel)
{
    if( aClass == nil )
        return;
    
    Method orig_method = nil, alt_method = nil;
    
    // First, look for the methods
    orig_method = class_getInstanceMethod(aClass, orig_sel);
    alt_method = class_getInstanceMethod(aClass, alt_sel);
    
    // If both are found, swizzle them
    if ((orig_method != nil) && (alt_method != nil))
    {
        char *temp1;
        IMP temp2;
        
        temp1 = orig_method->method_types;
        orig_method->method_types = alt_method->method_types;
         
        temp2 = orig_method->method_imp;
        orig_method->method_imp = alt_method->method_imp;
        alt_method->method_imp = temp2;
    }
}