Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #212 from ParsePlatform/nlutsenko.qvc.task
Browse files Browse the repository at this point in the history
Fix never succesfully completed task of -loadObjects in Query/Collection View Controllers.
  • Loading branch information
nlutsenko committed Dec 8, 2015
2 parents a10d3cc + f653e1f commit cc318dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ - (void)removeObjectsAtIndexPaths:(NSArray *)indexPaths {
self.loading = YES;
[self objectsWillLoad];

BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource];

PFQuery *query = [self queryForCollection];
[self _alterQuery:query forLoadingPage:page];

BFTaskCompletionSource PF_GENERIC(NSArray<__kindof PFObject *>*)*source = [BFTaskCompletionSource taskCompletionSource];
[query findObjectsInBackgroundWithBlock:^(NSArray *foundObjects, NSError *error) {
if (![Parse isLocalDatastoreEnabled] &&
query.cachePolicy != kPFCachePolicyCacheOnly &&
Expand Down Expand Up @@ -266,9 +266,12 @@ - (void)removeObjectsAtIndexPaths:(NSArray *)indexPaths {
[self objectsDidLoad:error];
[self.refreshControl endRefreshing];

[source setError:error];
if (error) {
[source trySetError:error];
} else {
[source trySetResult:foundObjects];
}
}];

return source.task;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ - (void)clear {
self.loading = YES;
[self objectsWillLoad];

BFTaskCompletionSource *source = [BFTaskCompletionSource taskCompletionSource];

PFQuery *query = [self queryForTable];
[self _alterQuery:query forLoadingPage:page];

BFTaskCompletionSource PF_GENERIC(NSArray<__kindof PFObject *>*)*source = [BFTaskCompletionSource taskCompletionSource];
[query findObjectsInBackgroundWithBlock:^(NSArray *foundObjects, NSError *error) {
if (![Parse isLocalDatastoreEnabled] &&
query.cachePolicy != kPFCachePolicyCacheOnly &&
Expand Down Expand Up @@ -252,7 +252,11 @@ - (void)clear {
[self objectsDidLoad:error];
[self.refreshControl endRefreshing];

[source setError:error];
if (error) {
[source trySetError:error];
} else {
[source trySetResult:foundObjects];
}
}];

return source.task;
Expand Down

0 comments on commit cc318dd

Please sign in to comment.