Create a gist now

Instantly share code, notes, and snippets.

@jspahrsummers /new.m Secret forked from tonyarnold/new.m
Last active Dec 16, 2015

What would you like to do?
RACSignal *milestoneSignal = [[[[[RACAble(self.eventManagedObjectID)
distinctUntilChanged]
flattenMap:^(NSManagedObjectID *nextEventManagedObjectID) {
@strongify(self);
if (TCBIsEmpty(nextEventManagedObjectID)) {
return [RACSignal error:[NSError errorWithDomain:WhateverDomain code:EmptyManagedObjectID userInfo:nil]];
}
NSError *objectRetrievalError;
TBDMilestone *milestone = (TBDMilestone *)[self.controllerManagedObjectContext existingObjectWithID:nextEventManagedObjectID error:&objectRetrievalError];
if (TCBIsEmpty(milestone)) {
return [RACSignal error:objectRetrievalError];
}
return [RACSignal return:milestone];
}]
doError:^(NSError *error) {
TCBLogError(error);
[[RACScheduler mainThreadScheduler] schedule:^{
self.startDate = [NSDate date];
}];
}]
retry]
replayLast];
RAC(self.label) = [[milestoneSignal
map:^(TBDMilestone *milestone) {
return milestone.label;
}]
deliverOn:[RACScheduler mainThreadScheduler]];
RAC(self.photo) = [[milestoneSignal
map:^(TBDMilestone *milestone) {
return [UIImage imageWithData:milestone.photo.data];
}]
deliverOn:[RACScheduler mainThreadScheduler]];
RAC(self.startDate) = [[milestoneSignal
map:^(TBDMilestone *milestone) {
return milestone.startedAt;
}]
deliverOn:[RACScheduler mainThreadScheduler]];
RAC(self.milestone) = [[RACAble(self.eventManagedObjectID) distinctUntilChanged] map:^TBDMilestone *(NSManagedObjectID *nextEventManagedObjectID) {
@strongify(self);
if (TCBIsEmpty(nextEventManagedObjectID)) {
return nil;
}
NSError *objectRetrievalError;
TBDMilestone *milestone = (TBDMilestone *)[self.controllerManagedObjectContext existingObjectWithID:nextEventManagedObjectID error:&objectRetrievalError];
if (TCBIsEmpty(milestone)) {
TCBLogError(objectRetrievalError);
}
return milestone;
}];
[RACAbleWithStart(self.milestone) subscribeNext :^(TBDMilestone *nextMilestone) {
@strongify(self);
self.label = nextMilestone.label;
self.photo = [UIImage imageWithData:nextMilestone.photo.data];
self.startDate = TCBIsNotEmpty(nextMilestone) ? nextMilestone.startedAt :[NSDate date];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment