Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Using rac_lift with methods that accept primitive types? #503

Closed
tonyarnold opened this issue May 21, 2013 · 4 comments
Closed

Comments

@tonyarnold
Copy link
Contributor

Hi Guys, is it possible to use rac_lift (or some variant) to replace a call to subscribeNext?

Concrete example: Can I make something like this more succinct?

[[[RACAbleWithStart(self.tickFrequency) distinctUntilChanged] deliverOn:[RACScheduler mainThreadScheduler]] subscribeNext:^(NSNumber *x) {
    @strongify(self);
    [self setNeedsDisplay:YES];
}];
@alanjrogers
Copy link
Member

@tonyarnold You sure can! I think the code below will work.

RACSignal *tickSignal = [[[RACAbleWithStart(self.tickFrequency) 
    distinctUntilChanged]
    mapReplace:@YES]
    deliverOn:RACScheduler.mainThreadScheduler];

[self rac_liftSelector:@selector(setNeedsDisplay:) withObjects:tickSignal];

That will effectively call [self setNeedsDisplay:YES] every time self.tickSignal is changed.

@jspahrsummers will pipe up If I'm wrong 😀

PS. I threw in some dot syntax cause I know how much you ❤️ it.

@tonyarnold
Copy link
Contributor Author

Wait wait wait, that's more code. sigh Sometimes I understand, sometimes I do not.

I hope you and your dots are happy together! 🚪

(The code works fine, thanks!)

@alanjrogers
Copy link
Member

It's not more code, I just spread it over more lines :D

@jspahrsummers
Copy link
Member

We prefer the more declarative style (selector lifting), because it makes the intention extremely clear. You're invoking -setNeedsDisplay: over time, but the -subscribeNext: obfuscates that somewhat.

Using rac_liftSelector: also neatly avoids the weakify/strongify dance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants