Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Safety checks in UIView. Make block copying non atomic.

  • Loading branch information...
commit bab7a36d81ebf8b152188c36eb201320a3a59693 1 parent d0d8126
@zwaldowski authored
View
2  BlocksKit/NSObject+AssociatedObjects.m
@@ -13,7 +13,7 @@ - (void)associateValue:(id)value withKey:(void *)key {
}
- (void)associateCopyOfValue:(id)value withKey:(void *)key {
- objc_setAssociatedObject(self, key, value, OBJC_ASSOCIATION_COPY);
+ objc_setAssociatedObject(self, key, value, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (void)weaklyAssociateValue:(id)value withKey:(void *)key {
View
16 BlocksKit/UIView+BlocksKit.m
@@ -17,10 +17,17 @@ @implementation UIView (BlocksKit)
- (void)whenTouches:(NSUInteger)numberOfTouches tapped:(NSUInteger)numberOfTaps handler:(BKBlock)block {
self.userInteractionEnabled = YES;
+ block = [block copy];
+
UITapGestureRecognizer *gesture = [UITapGestureRecognizer recognizerWithHandler:^(UIGestureRecognizer *sender, UIGestureRecognizerState state, CGPoint location) {
block();
}];
+ BK_RELEASE(block);
+
+ [gesture setNumberOfTouchesRequired:numberOfTouches];
+ [gesture setNumberOfTapsRequired:numberOfTaps];
+
[[self.gestureRecognizers select:^BOOL(id obj) {
if ([obj isKindOfClass:[UITapGestureRecognizer class]]) {
BOOL rightTouches = ([(UITapGestureRecognizer *)obj numberOfTouchesRequired] == numberOfTouches);
@@ -31,9 +38,6 @@ - (void)whenTouches:(NSUInteger)numberOfTouches tapped:(NSUInteger)numberOfTaps
}] each:^(id obj) {
[gesture requireGestureRecognizerToFail:(UITapGestureRecognizer *)obj];
}];
-
- [gesture setNumberOfTouchesRequired:numberOfTouches];
- [gesture setNumberOfTapsRequired:numberOfTaps];
[self addGestureRecognizer:gesture];
}
@@ -48,16 +52,22 @@ - (void)whenDoubleTapped:(BKBlock)block {
- (void)whenTouchedDown:(BKTouchBlock)block {
self.userInteractionEnabled = YES;
+ if (!block)
+ block = nil;
[self associateCopyOfValue:block withKey:kViewTouchDownBlockKey];
}
- (void)whenTouchMove:(BKTouchBlock)block {
self.userInteractionEnabled = YES;
+ if (!block)
+ block = nil;
[self associateCopyOfValue:block withKey:kViewTouchMoveBlockKey];
}
- (void)whenTouchedUp:(BKTouchBlock)block {
self.userInteractionEnabled = YES;
+ if (!block)
+ block = nil;
[self associateCopyOfValue:block withKey:kViewTouchUpBlockKey];
}
Please sign in to comment.
Something went wrong with that request. Please try again.