Created
June 3, 2012 19:17
-
-
Save pilky/2864689 to your computer and use it in GitHub Desktop.
Reactive Cocoa example with subscripting hack
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
Basically I can turn this: | |
[[[[loginResult | |
where:^(id x) { | |
return [x hasError]; | |
}] | |
select:^(id x) { | |
return [x error]; | |
}] | |
injectObjectWeakly:self] | |
subscribeNext:^(RACTuple *t) { | |
GHDLoginViewController *self = t.last; | |
self.loginFailedHidden = NO; | |
NSLog(@"error logging in: %@", t.first); | |
}]; | |
Into this: | |
[loginResult | |
.where[(id)^(id x) { | |
return [x hasError]; | |
}] | |
.select[(id)^(id x) { | |
return [x error]; | |
}] | |
.injectObjectWeakly[self] | |
.subscribeNext[(id)^(RACTuple *t) { | |
GHDLoginViewController *self = t.last; | |
self.loginFailedHidden = NO; | |
NSLog(@"error logging in: %@", t.first); | |
}] run]; | |
I abuse subscripting to do this. On the plus side it means no real nesting problems. On the downside it means you have to put (id) in front of any block and if you're not assigning you have to have something like the -run method which does nothing but silences a compiler warning about side effects. Tiny bit hacky (requires some proxy stuff) but doable (at least on 10.7 and 10.8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment