Last active
December 17, 2015 18:29
-
-
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.
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.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