Created
October 18, 2014 04:29
-
-
Save uasi/581573d7e86b8325bbbd to your computer and use it in GitHub Desktop.
CDEvents+RACExtensions
This file contains hidden or 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
// | |
// CDEvents+RACExtensions.h | |
// Kobito | |
// | |
// Copyright (c) 2014 Increments Inc. All rights reserved. | |
// | |
#import <CDEvents/CDEvents.h> | |
@class RACSignal; | |
@interface CDEvents (RACExtensions) | |
+ (RACSignal *)rac_signalForEventsWithURLs:(NSArray *)URLs; | |
+ (RACSignal *)rac_signalForEventsWithURLs:(NSArray *)URLs onRunLoop:(NSRunLoop *)runLoop; | |
@end |
This file contains hidden or 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
// | |
// CDEvents+RACExtensions.m | |
// Kobito | |
// | |
// Copyright (c) 2014 Increments Inc. All rights reserved. | |
// | |
#import "CDEvents+RACExtensions.h" | |
#import <CDEvents/CDEvents.h> | |
#import <objc/runtime.h> | |
@implementation CDEvents (RACExtensions) | |
+ (RACSignal *)rac_signalForEventsWithURLs:(NSArray *)URLs { | |
return [[self class] rac_signalForEventsWithURLs:URLs onRunLoop:[NSRunLoop currentRunLoop]]; | |
} | |
+ (RACSignal *)rac_signalForEventsWithURLs:(NSArray *)URLs onRunLoop:(NSRunLoop *)runLoop { | |
RACReplaySubject *subject = [RACReplaySubject subject]; | |
CDEvents *watcher = [[[self class] alloc] initWithURLs:URLs block:^(CDEvents *watcher, CDEvent *event) { | |
[subject sendNext:RACTuplePack(watcher, event)]; | |
} onRunLoop:runLoop]; | |
// Associate `watcher` with `subject` to maintain strong reference to it. | |
objc_setAssociatedObject(subject, _cmd, watcher, OBJC_ASSOCIATION_RETAIN); | |
return subject; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment