Last active
August 29, 2015 14:23
-
-
Save hsavit1/a4da71c406eea09b5173 to your computer and use it in GitHub Desktop.
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
// creates a signal that fetches an image in the background, delivering | |
// it on the UI thread. This signal 'cancels' itself if the cell is re-used before the | |
// image is downloaded. | |
-(RACSignal *)signalForImage:(NSURL *)imageUrl { | |
RACScheduler *scheduler = [RACScheduler schedulerWithPriority:RACSchedulerPriorityBackground]; | |
RACSignal *imageDownloadSignal = [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
NSData *data = [NSData dataWithContentsOfURL:imageUrl]; | |
UIImage *image = [UIImage imageWithData:data]; | |
//now we can tell the SUBSCRIBER to do something!! This is the key with the signals | |
[subscriber sendNext:image]; | |
[subscriber sendCompleted]; | |
return nil; | |
}] subscribeOn:scheduler]; | |
return [[imageDownloadSignal | |
takeUntil:self.rac_prepareForReuseSignal] | |
deliverOn:[RACScheduler mainThreadScheduler]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment