Skip to content

Instantly share code, notes, and snippets.

@uasi
Created October 18, 2014 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uasi/581573d7e86b8325bbbd to your computer and use it in GitHub Desktop.
Save uasi/581573d7e86b8325bbbd to your computer and use it in GitHub Desktop.
CDEvents+RACExtensions
//
// 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
//
// 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