Skip to content

Instantly share code, notes, and snippets.

[[[NSNotificationCenter.defaultCenter
rac_addObserverForName:NSApplicationDidBecomeActiveNotification object:nil]
takeUntil:self.rac_willDeallocSignal]
subscribeNext:^(NSNotification *notification) {
NSLog(@"got ur note bro: %@", notification);
}];
// some other shit
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.770437 0.783913 0.778299 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>Inconsolata - 13.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.770437 0.783913 0.778299 1</string>
@joshaber
joshaber / gist:5228077
Created March 23, 2013 15:20
Parallel dependent tasks
__block NSArray *databaseObjects;
__block NSArray *fileContents;
NSOperationQueue *backgroundQueue = [[NSOperationQueue alloc] init];
NSBlockOperation *operation1 = [NSBlockOperation blockOperationWithBlock:^{
databaseObjects = [databaseClient fetchObjectsMatchingPredicate:predicate];
}];
NSBlockOperation *operation2 = [NSBlockOperation blockOperationWithBlock:^{
NSMutableArray *filesInProgress = [NSMutableArray array];
@joshaber
joshaber / gist:5226626
Last active December 15, 2015 07:49
ReactivePersistence?
// The basics
[[self.connection fetch:@"the-answer"] subscribeNext:^(NSNumber *x) {
NSLog(@"The answer is %@", x);
}];
[[self.connection writeObject:@42 forKey:@"the-answer"] subscribeCompleted:^{
NSLog(@"Wrote it.");
}];
// Signal for changes to the object at a key
RAC(self.someView.hidden) = [RACAbleWithStart(self.someArray) map:^(NSArray *x) {
return x.count == 0;
}];
RAC(view, hidden) = [arraySignal map:^(NSArray *x) {
return x.count == 0;
}];
[[[[[[[[[[self.searchTextField
rac_textSignal]
filter:^BOOL(NSString *value) {
return value.length > 2;
}]
doNext:^(NSString *x) {
NSLog(@"[%@] Text Changed: %@", [NSThread currentThread], x);
}]
throttle: .6]
doNext:^(id x) {
@joshaber
joshaber / gist:4394046
Created December 28, 2012 02:49
NSEvent+RACSignals
@implementation NSEvent (RACSignals)
+ (id<RACSignal>)rac_signalForEventsMatchingMask:(NSEventMask)eventMask {
return [RACSignal createSignal:^(id<RACSubscriber> subscriber) {
id monitor = [NSEvent addLocalMonitorForEventsMatchingMask:eventMask handler:^(NSEvent *event) {
[subscriber sendNext:event];
return event;
}];
return [RACDisposable disposableWithBlock:^{
@joshaber
joshaber / gist:4238342
Created December 8, 2012 02:54
ReactiveCocoa stopwatch with reset
self.startButton.rac_command = [RACCommand command];
self.stopButton.rac_command = [RACCommand command];
self.resetButton.rac_command = [RACCommand command];
static const CGFloat interval = 0.01;
__unsafe_unretained id weakSelf = self;
// Signal id -> Signal Signal Number
// Map each click of the start button to a signal that fires at our interval
// and stops when the stop button's clicked.
id<RACSignal> start = [self.startButton.rac_command map:^(id _) {
@joshaber
joshaber / gist:4230872
Created December 7, 2012 04:57
ReactiveCocoa stopwatch
self.startButton.rac_command = [RACCommand command];
self.stopButton.rac_command = [RACCommand command];
__unsafe_unretained id weakSelf = self;
id<RACSignal> tick = [[[[self.startButton.rac_command
map:^(id _) {
RTAFirstView *strongSelf = weakSelf;
// Map each start button click to a new signal that fires every second
// and stops when the stop button is clicked.
return [[RACSignal interval:1] takeUntil:strongSelf.stopButton.rac_command];