Skip to content

Instantly share code, notes, and snippets.

@rbaulin
Last active December 17, 2015 18:29
Show Gist options
  • Save rbaulin/5654114 to your computer and use it in GitHub Desktop.
Save rbaulin/5654114 to your computer and use it in GitHub Desktop.
Find out what is item's URL and load it when ready. Oh yeah, and show me a loading screen if it takes more than 1 second for preparation. And call off the fuss if item has changed. Hell yeah, ReactiveCocoa.
self.currentItem = item;
RACSignal *itemChanged = [[RACObserve(self, currentItem) skip:1] take:1];
// prepare item until switched to other item
RACSignal *itemReady = [[item rac_prepareItem] takeUntil:itemChanged];
// show description if preparation takes more than 1 second
[[[[[RACSignal interval:1.] take:1]
takeUntil:itemReady]
deliverOn:[RACScheduler mainThreadScheduler]]
subscribeNext:^(id x) {
[self setLoadingStateWithTitle:@"Fetching URL" animated:YES];
}];
// load item when ready
[itemReady
subscribeNext:^(id<FDPlayerItem> readyItem) {
// ready
[self loadAssetFromURL:[item url]];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment