Skip to content

Instantly share code, notes, and snippets.

View ashfurrow's full-sized avatar

Ash Furrow ashfurrow

View GitHub Profile
#########################
# .gitignore file for Xcode4 / OS X Source projects
#
# Version 2.0
# For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
#
# 2013 updates:
# - fixed the broken "save personal Schemes"
#
# NB: if you are storing "built" products, this WILL NOT WORK,
@ashfurrow
ashfurrow / gist:5404679
Last active December 16, 2015 08:19
Subscribing to a text field's signal
[self.textField.rac_textSignal subscribeNext:^(NSString *value) {
NSLog(@"Text field has been updated: %@", value);
}];
@ashfurrow
ashfurrow / gist:5569937
Last active December 17, 2015 06:59
Filtering a text field's signal
[[self.textField.rac_textSignal filter:^BOOL(NSString *value) {
return [value length] >= 3;
}] subscribeNext:^(NSString *value) {
NSLog(@"Text field has been updated: %@", value);
}];
@ashfurrow
ashfurrow / gist:5569942
Last active December 17, 2015 06:59
Combining two signals.
[[RACSignal
combineLatest:@[self.firstNameField.rac_textSignal, self.lastNameField.rac_textSignal]
reduce:^(NSString *firstName, NSString *lastName){
return @(firstName.length > 0 && lastName.length > 0);
}] toProperty:@"enabled" onObject:self.button];
@ashfurrow
ashfurrow / gist:5621776
Last active December 17, 2015 14:08
ReactiveCocoa Chaining Example
RAC(self.textField.text) = [[[RACSignal interval:1] startWith:[NSDate date]] map:^id(NSDate *value) {
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:value];
return [NSString stringWithFormat:@"%d:%02d", dateComponents.minute, dateComponents.second];
}];
@ashfurrow
ashfurrow / gist:5621791
Created May 21, 2013 17:51
ReactiveCocoa Chaining Example
RACSignal *intervalSignal = [RACSignal interval:1];
RACSignal *startedIntervalSignal = [intervalSignal startWith:[NSDate date]];
RACSignal *mappedIntervalSignal = [startedIntervalSignal map:^id(NSDate *value) {
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:value];
return [NSString stringWithFormat:@"%d:%02d", dateComponents.minute, dateComponents.second];
}];
RAC(self.textField.text) = mappedIntervalSignal;
@ashfurrow
ashfurrow / gist:5621801
Last active December 17, 2015 14:08
ReactiveCocoa Splitting Example
RACSignal *dateComponentsSignal = [[[RACSignal interval:1] startWith:[NSDate date]] map:^id(NSDate *value) {
NSDateComponents *dateComponents = [[NSCalendar currentCalendar] components:NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:value];
return dateComponents;
}];
RAC(self.minuteTextField.text) = [dateComponentsSignal map:^id(NSDateComponents *dateComponents) {
return [NSString stringWithFormat:@"%d", dateComponents.minute];
}];
RAC(self.secondTextField.text) = [dateComponentsSignal map:^id(NSDateComponents *dateComponents) {
@ashfurrow
ashfurrow / gist:5621819
Created May 21, 2013 17:54
ReactiveCocoa Combining Example
RAC(self.submitButton.enabled) = [RACSignal combineLatest:@[self.usernameField.rac_textSignal, self.passwordField.rac_textSignal] reduce:^id(NSString *userName, NSString *password) {
return @(userName.length >= 6 && password.length >= 6);
}];
@ashfurrow
ashfurrow / gist:5621841
Last active December 17, 2015 14:08
ReactiveCocoa RACSubject Example
self.gestureRecognizerIsRunningSubject = [RACSubject subject];
self.gestureRecognizerValueSubject = [RACSubject subject];
RAC(self.someView.frame) = [self.gestureRecognizerValueSubject map:^id(NSValue *value) {
CGPoint location = [value CGPointValue];
CGFloat size = 100.0f;
return [NSValue valueWithCGRect:CGRectMake(location.x - size/2.0f, location.y - size/2.0f, size, size)];
}];
@ashfurrow
ashfurrow / gist:5621995
Last active December 17, 2015 14:09
ReactiveCocoa RACSubject Example
-(void)gestureRecognizerReceivedTouch:(UIPanGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
[self.gestureRecognizerIsRunningSubject sendNext:@(YES)];
}
else if (recognizer.state == UIGestureRecognizerStateChanged) {
[self.gestureRecognizerValueSubject sendNext:[NSValue valueWithCGPoint:[recognizer locationInView:self.view]]];
}
else if (recognizer.state == UIGestureRecognizerStateEnded) {