-
Notifications
You must be signed in to change notification settings - Fork 28
/
KWBlock.m
63 lines (44 loc) · 974 Bytes
/
KWBlock.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
//
// Licensed under the terms in License.txt
//
// Copyright 2010 Allen Ding. All rights reserved.
//
#import "KWBlock.h"
@interface KWBlock()
#pragma mark -
#pragma mark Properties
@property (nonatomic, readonly, assign) KWVoidBlock block;
@end
@implementation KWBlock
#pragma mark -
#pragma mark Initializing
- (id)initWithBlock:(KWVoidBlock)aBlock {
if ((self = [super init])) {
block = Block_copy(aBlock);
}
return self;
}
+ (id)blockWithBlock:(KWVoidBlock)aBlock {
return [[[self alloc] initWithBlock:aBlock] autorelease];
}
- (void)dealloc {
Block_release(block);
[super dealloc];
}
#pragma mark -
#pragma mark Properties
@synthesize block;
#pragma mark -
#pragma mark Calling Blocks
- (void)call {
block();
}
@end
#pragma mark -
#pragma mark Creating Blocks
KWBlock *theBlock(KWVoidBlock aBlock) {
return lambda(aBlock);
}
KWBlock *lambda(KWVoidBlock aBlock) {
return [KWBlock blockWithBlock:aBlock];
}