Permalink
Browse files

Cleanup.

  • Loading branch information...
1 parent 9c27a6f commit ee2bd03a01ee7752b208c90ce12058b27d3c008e @omnivector omnivector committed Jul 17, 2011
Showing with 20 additions and 8 deletions.
  1. +2 −2 Source/UIControl-BKAdditions.h
  2. +18 −6 Source/UIControl-BKAdditions.m
@@ -3,15 +3,15 @@
// BlockKit
//
// Created by Nick Paulson on 7/16/11.
-// Copyright 2011 Linebreak. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "BKTypes.h"
+
@interface UIControl (BKAdditions)
- (void)addActionForControlEvents:(UIControlEvents)controlEvents usingBlock:(BKVoidBlock)block;
-- (void)removeAllBlocks;
+- (void)removeAllActionBlocks;
@end
@@ -3,31 +3,40 @@
// BlockKit
//
// Created by Nick Paulson on 7/16/11.
-// Copyright 2011 Linebreak. All rights reserved.
//
#import "UIControl-BKAdditions.h"
#import "NSObject-BKAdditions.h"
+
+// Private Methods
@interface BKVoidBlockWrapper : NSObject
+
@property (nonatomic, copy) BKVoidBlock block;
@property (nonatomic, retain) id userInfo;
- (id)initWithBlock:(BKVoidBlock)aBlock userInfo:(id)someUserInfo;
- (void)performBlock;
+
@end
+
@implementation BKVoidBlockWrapper
@synthesize block;
@synthesize userInfo;
+#pragma mark Initialization
+
- (id)initWithBlock:(BKVoidBlock)aBlock userInfo:(id)someUserInfo;
{
- if ((self = [super init])) {
- block = [aBlock copy];
- userInfo = [someUserInfo retain];
+ if (!(self = [super init])) {
+ return nil;
}
+
+ block = [aBlock copy];
+ userInfo = [someUserInfo retain];
+
return self;
}
@@ -50,11 +59,13 @@ - (void)performBlock;
@end
+
@implementation UIControl (BKAdditions)
+ (void)load;
{
static dispatch_once_t onceToken;
+
dispatch_once(&onceToken, ^{
[self swizzleInstanceSelector:@selector(dealloc) withNewSelector:@selector(bk_dealloc)];
});
@@ -66,9 +77,10 @@ - (void)addActionForControlEvents:(UIControlEvents)controlEvents usingBlock:(BKV
[self addTarget:blockWrapper action:@selector(performBlock) forControlEvents:controlEvents];
}
-- (void)removeAllBlocks;
+- (void)removeAllActionBlocks;
{
NSArray *targets = [[self.allTargets copy] autorelease];
+
for (id currTarget in targets) {
if ([currTarget isKindOfClass:[BKVoidBlockWrapper class]]) {
UIControlEvents controlEvents = [[(BKVoidBlockWrapper *)currTarget userInfo] integerValue];
@@ -80,7 +92,7 @@ - (void)removeAllBlocks;
- (void)bk_dealloc;
{
- [self removeAllBlocks];
+ [self removeAllActionBlocks];
[self bk_dealloc];
}

0 comments on commit ee2bd03

Please sign in to comment.