-
Notifications
You must be signed in to change notification settings - Fork 39
/
NSObject+Be.m
63 lines (45 loc) · 1.15 KB
/
NSObject+Be.m
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// NSObject+Be.m
//
// Created by Tyler Neylon on 6/15/09.
// Copyright 2009 Bynomial.
//
#import "NSObject+Be.h"
@interface BeProxy : NSProxy {
id target;
}
+ (BeProxy *)beProxyForClass:(Class)class;
- (void)forwardInvocation:(NSInvocation *)anInvocation;
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
@end
@implementation BeProxy
+ (BeProxy *)beProxyForClass:(Class)class {
BeProxy *beProxy = [BeProxy alloc];
beProxy->target = [class alloc];
return beProxy;
}
// We assume the method called is an init method. The return value
// may be a new value for self.
- (void)forwardInvocation:(NSInvocation *)anInvocation {
[anInvocation setTarget:target];
[anInvocation invoke];
id object;
[anInvocation getReturnValue:(void *)&object];
[object autorelease];
[self release];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
return [target methodSignatureForSelector:aSelector];
}
@end
@implementation NSObject (Be)
+ (id)be {
return [BeProxy beProxyForClass:[self class]];
}
+ (id)beInit {
return [[[self class] new] autorelease];
}
- (id)beCopy {
return [[self copy] autorelease];
}
@end