Created
October 21, 2014 12:05
-
-
Save Igor-Palaguta/4bd53200dca0e9a31b10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UINavigationController+RACSignalSupport.h" | |
#import <ReactiveCocoa/ReactiveCocoa.h> | |
#import <ReactiveCocoa/RACDelegateProxy.h> | |
#import <ReactiveCocoa/NSObject+RACDescription.h> | |
#import <objc/runtime.h> | |
@implementation UIImagePickerController (RACSignalSupport) | |
-(Protocol*)rac_delegateProtocol | |
{ | |
return @protocol(UIImagePickerControllerDelegate); | |
} | |
@end | |
@implementation UINavigationController (RACSignalSupport) | |
static void RACUseDelegateProxy(UINavigationController *self) | |
{ | |
if (self.delegate == self.rac_delegateProxy) return; | |
self.rac_delegateProxy.rac_proxiedDelegate = self.delegate; | |
self.delegate = (id)self.rac_delegateProxy; | |
} | |
-(Protocol*)rac_delegateProtocol | |
{ | |
return @protocol(UINavigationControllerDelegate); | |
} | |
-(RACDelegateProxy*)rac_delegateProxy | |
{ | |
RACDelegateProxy *proxy = objc_getAssociatedObject(self, _cmd); | |
if (proxy == nil) { | |
proxy = [[RACDelegateProxy alloc] initWithProtocol:[self rac_delegateProtocol]]; | |
objc_setAssociatedObject(self, _cmd, proxy, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
} | |
return proxy; | |
} | |
-(RACSignal*)rac_willShowViewControllerSignal | |
{ | |
RACSignal* signal_ = | |
[ [ [ self.rac_delegateProxy | |
signalForSelector:@selector(navigationController:willShowViewController:animated:)] | |
reduceEach: | |
^( UINavigationController* navigation_controller_, UIViewController* controller_, NSNumber* _ ) | |
{ | |
return controller_; | |
}] | |
takeUntil: self.rac_willDeallocSignal ]; | |
RACUseDelegateProxy(self); | |
return signal_; | |
} | |
-(RACSignal*)rac_didShowViewControllerSignal | |
{ | |
RACSignal* signal_ = | |
[ [ [ self.rac_delegateProxy | |
signalForSelector:@selector(navigationController:didShowViewController:animated:)] | |
reduceEach: | |
^( UINavigationController* navigation_controller_, UIViewController* controller_, NSNumber* _ ) | |
{ | |
return controller_; | |
}] | |
takeUntil: self.rac_willDeallocSignal ]; | |
RACUseDelegateProxy(self); | |
return signal_; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment