Skip to content
This repository has been archived by the owner on May 21, 2020. It is now read-only.

Commit

Permalink
Minor cleanup and slight optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
schwa committed Dec 27, 2013
1 parent a651427 commit 31ee7d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 0 additions & 2 deletions NSObject+KVOBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,5 @@ typedef void (^KVOFullBlock)(NSString *keyPath, id object, NSDictionary *change)
/// One shot blocks remove themselves after they've been fired once.
- (id)addOneShotKVOBlockForKeyPath:(NSString *)inKeyPath options:(NSKeyValueObservingOptions)inOptions handler:(KVOFullBlock)inHandler;

- (void)KVODump;

@end

20 changes: 7 additions & 13 deletions NSObject+KVOBlock.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (id)addKVOBlockForKeyPath:(NSString *)inKeyPath options:(NSKeyValueObservingOp
NSParameterAssert(inKeyPath);
NSParameterAssert([NSThread isMainThread]); // TODO -- remove and grow a pair.

CKVOBlockHelper *theHelper = [self helper:YES];
CKVOBlockHelper *theHelper = KVOBlockHelperForObject(self, YES);
NSParameterAssert(theHelper != NULL);

CKVOToken *theToken = [theHelper insertNewTokenForKeyPath:inKeyPath block:inHandler];
Expand All @@ -84,7 +84,7 @@ - (id)addKVOBlockForKeyPath:(NSString *)inKeyPath options:(NSKeyValueObservingOp
- (void)removeKVOBlockForToken:(CKVOToken *)inToken
{
NSParameterAssert([NSThread isMainThread]); // TODO -- remove and grow a pair.
CKVOBlockHelper *theHelper = [self helper:NO];
CKVOBlockHelper *theHelper = KVOBlockHelperForObject(self, NO);
NSParameterAssert(theHelper != NULL);

void *theContext = inToken.context;
Expand All @@ -110,22 +110,16 @@ - (id)addOneShotKVOBlockForKeyPath:(NSString *)inKeyPath options:(NSKeyValueObse
return(theToken);
}

- (void)KVODump
{
CKVOBlockHelper *theHelper = [self helper:NO];
[theHelper dump];
}

#pragma mark -

- (CKVOBlockHelper *)helper:(BOOL)inCreate
{
CKVOBlockHelper *theHelper = objc_getAssociatedObject(self, &KVO);
static CKVOBlockHelper *KVOBlockHelperForObject(NSObject *object, BOOL inCreate)
{
CKVOBlockHelper *theHelper = objc_getAssociatedObject(object, &KVO);
if (theHelper == NULL && inCreate == YES)
{
theHelper = [[CKVOBlockHelper alloc] initWithObject:self];
theHelper = [[CKVOBlockHelper alloc] initWithObject:object];

objc_setAssociatedObject(self, &KVO, theHelper, OBJC_ASSOCIATION_RETAIN);
objc_setAssociatedObject(object, &KVO, theHelper, OBJC_ASSOCIATION_RETAIN);
}
return(theHelper);
}
Expand Down

0 comments on commit 31ee7d1

Please sign in to comment.