Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
omnivector committed Jul 17, 2011
1 parent 9c27a6f commit ee2bd03
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Source/UIControl-BKAdditions.h
Expand Up @@ -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
24 changes: 18 additions & 6 deletions Source/UIControl-BKAdditions.m
Expand Up @@ -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;
}

Expand All @@ -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)];
});
Expand All @@ -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];
Expand All @@ -80,7 +92,7 @@ - (void)removeAllBlocks;

- (void)bk_dealloc;
{
[self removeAllBlocks];
[self removeAllActionBlocks];

[self bk_dealloc];
}
Expand Down

0 comments on commit ee2bd03

Please sign in to comment.