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
//example of a dynamic signal created with RAC | |
//called 'dynamic' because it's user created. You can turn any asynchronus action into a signal | |
//heres a typical example | |
RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
id operation = asynchronusAction(^(id asyncActionResult, NSError *error) { | |
if (error) { | |
[subscriber sendError:error]; |
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
/* | |
RACImmediateScheduler | |
Private scheduler used in ReactiveCocoa internally and and supports only synchronous scheduling. It simply execute the block right away. Delayed scheduling works by blocking current thread with -[NSThread sleepUntilDate:]. Obviously, there's no way to control cancellation of such scheduling, so disposables retuned by this scheduler will do nothing (in fact, scheduling methods of this scheduler return nil). | |
RACQueueScheduler | |
This scheduler uses GCD queues for scheduling blocks. It's functionality is pretty straightforward if you know what GCD does. It's actually a very thin layer over dispatching blocks in GCD queues. | |
RACSubscriptionScheduler | |
Another private scheduler used by framework internally. It forwards scheduling to current thread's scheduler (scheduler can be associated with the thread) if it exists or to default background queue scheduler. | |
*/ |
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
- (RACSignal *)topQuestions{ | |
RACSignal *signal = [[RSOWebServices sharedServices] fetchQuestionsWithTag:nil]; | |
return [self questionsForSignal:signal]; | |
} | |
- (RACSignal *)fetchQuestionsWithTag:(NSString *)tag{ | |
NSURL *fetchQuestionURL = [self createRelativeURLWithTag:tag]; | |
@weakify(self); | |
RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
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
@implementation ViewController | |
static MyContext = &MyContext; | |
- (void)configure | |
[myPerson addObserver:self | |
forKeyPath:NSStringFromSelector(@selector(firstName)) | |
options:NSKeyValueObservingOptionNew | |
context:MyContext]; | |
} |
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
// | |
// RACSignal.h | |
// ReactiveCocoa | |
// | |
// Created by Josh Abernathy on 3/1/12. | |
// Copyright (c) 2012 GitHub, Inc. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "RACStream.h" |
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
- (RACSignal *)fetchJSONFromURL:(NSURL *)url { | |
NSLog(@"Fetching: %@",url.absoluteString); | |
// 1 | |
return [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
// 2 | |
NSURLSessionDataTask *dataTask = [self.session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { | |
// TODO: Handle retrieved data | |
}]; | |
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
@interface RAC_TableViewController () | |
@property (nonatomic) SRGViewModel *viewModel; | |
@end | |
@implementation RAC_TableViewController | |
- (void)awakeFromNib { | |
@weakify(self) | |
self.viewModel = [[SRGViewModel alloc] init]; | |
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
// KVO based observing | |
RACSignal *kvoPropertySignal = RACObserve(object, property); | |
// dynamic signal with async action with block-based callback | |
RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
id operation = asynchronusAction(^(id asyncActionResult, NSError *error) { | |
if (error) { | |
[subscriber sendError:error]; | |
} | |
else { |
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
__block NSArray *databaseObjects; | |
__block NSArray *fileContents; | |
NSOperationQueue *backgroundQueue = [[NSOperationQueue alloc] init]; | |
NSBlockOperation *databaseOperation = [NSBlockOperation blockOperationWithBlock:^{ | |
databaseObjects = [databaseClient fetchObjectsMatchingPredicate:predicate]; | |
}]; | |
NSBlockOperation *filesOperation = [NSBlockOperation blockOperationWithBlock:^{ | |
NSMutableArray *filesInProgress = [NSMutableArray array]; |
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
__block unsigned subscriptions = 0; | |
RACSignal *loggingSignal = [RACSignal createSignal:^ RACDisposable * (id<RACSubscriber> subscriber) { | |
subscriptions++; | |
[subscriber sendCompleted]; | |
return nil; | |
}]; | |
// Does not output anything yet | |
loggingSignal = [loggingSignal doCompleted:^{ |