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
[[[NSUserDefaultsController sharedUserDefaultsController] rac_subscribableForKeyPath:@"values.yourDefaultsKey" onObject:self] subscribeNext:(id x) { | |
// do the things | |
}]; |
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
// Here, rowView is a weak pointer to the view's superview. | |
RAC(self.layer.contents) = [[[[RACAble(self.rowView.selected) distinctUntilChanged] injectObjectWeakly:self] | |
doNext:^(RACTuple *x) { | |
CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"contents"]; | |
fade.duration = 0.15; | |
[[x.last layer] addAnimation:fade forKey:@"animateContents"]; | |
}] select:^id(RACTuple *x) { | |
return ([x.first boolValue] ? [self highlightedGradient] : [self standardGradient]); | |
}]; |
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
RAC(self.layer.contents) = [[[[[[RACAble(self.rowView) select:^(YourRowView *rowView) { | |
return RACAble(rowView, selected); | |
}] switch] distinctUntilChanged] injectObjectWeakly:self] | |
doNext:^(RACTuple *x) { | |
CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"contents"]; | |
fade.duration = 0.15; | |
[[x.last layer] addAnimation:fade forKey:@"animateContents"]; | |
}] select:^id(RACTuple *x) { | |
return ([x.first boolValue] ? [self highlightedGradient] : [self standardGradient]); | |
}]; |
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
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]; |
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
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 _) { |
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
@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:^{ |
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
[[[[[[[[[[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) { |
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
RAC(view, hidden) = [arraySignal map:^(NSArray *x) { | |
return x.count == 0; | |
}]; |
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
RAC(self.someView.hidden) = [RACAbleWithStart(self.someArray) map:^(NSArray *x) { | |
return x.count == 0; | |
}]; |
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
// 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 |