UIGestureRecognizer+RACSignalSupport.m 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // UIGestureRecognizer+RACSignalSupport.m
  3. // ReactiveObjC
  4. //
  5. // Created by Josh Vera on 5/5/13.
  6. // Copyright (c) 2013 GitHub. All rights reserved.
  7. //
  8. #import "UIGestureRecognizer+RACSignalSupport.h"
  9. #import <ReactiveObjC/RACEXTScope.h>
  10. #import "NSObject+RACDeallocating.h"
  11. #import "NSObject+RACDescription.h"
  12. #import "RACCompoundDisposable.h"
  13. #import "RACDisposable.h"
  14. #import "RACSignal.h"
  15. #import "RACSubscriber.h"
  16. @implementation UIGestureRecognizer (RACSignalSupport)
  17. - (RACSignal *)rac_gestureSignal {
  18. @weakify(self);
  19. return [[RACSignal
  20. createSignal:^(id<RACSubscriber> subscriber) {
  21. @strongify(self);
  22. [self addTarget:subscriber action:@selector(sendNext:)];
  23. [self.rac_deallocDisposable addDisposable:[RACDisposable disposableWithBlock:^{
  24. [subscriber sendCompleted];
  25. }]];
  26. return [RACDisposable disposableWithBlock:^{
  27. @strongify(self);
  28. [self removeTarget:subscriber action:@selector(sendNext:)];
  29. }];
  30. }]
  31. setNameWithFormat:@"%@ -rac_gestureSignal", RACDescription(self)];
  32. }
  33. @end