-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFLazyProxy.m
More file actions
45 lines (37 loc) · 831 Bytes
/
FLazyProxy.m
File metadata and controls
45 lines (37 loc) · 831 Bytes
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
#import "FLazyProxy.h"
@interface FLazyProxy () {
FLazyProxyResolver _resolver;
id _object;
BOOL _resolved;
}
@end
@implementation FLazyProxy
+ (instancetype)proxyWithBlock:(FLazyProxyResolver const)aResolver
{
FLazyProxy * const proxy = [self alloc];
NSParameterAssert(aResolver);
proxy->_resolver = aResolver;
return proxy;
}
- (id)_cy_object
{
if(__builtin_expect(!_resolved, 0)) {
_resolved = YES;
_object = _resolver();
}
return _object;
}
- (void)forwardInvocation:(NSInvocation *)anInvocation
{
[anInvocation setTarget:[self _cy_object]];
[anInvocation invoke];
}
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
return [[self _cy_object] methodSignatureForSelector:aSelector];
}
- (id)self
{
return [self _cy_object];
}
@end