Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method that returns BFTask #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions PFCloud+Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
//

#import <Parse/Parse.h>
#import <Parse/PFConstants.h>

@class BFTask;

@interface PFCloud (Cache)

+ (BFTask *)callFunctionInBackground:(NSString *)function withParameters:(NSDictionary *)parameters cachePolicy:(PFCachePolicy)cachePolicy;

/*
Calls the given cloud function with the parameters provided asynchronously and runs the callback when it is done.
@param function The function name to call.
Expand Down
15 changes: 15 additions & 0 deletions PFCloud+Cache.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@
#import "PFCloud+Cache.h"
#import "TMCache.h"
#import "NSData+MD5Digest.h"
#import "BFTask.h"
#import "BFTaskCompletionSource.h"

@implementation PFCloud (Cache)

#pragma mark - Public

+ (BFTask *) callFunctionInBackground:(NSString*)function withParameters:(NSDictionary*)parameters cachePolicy:(PFCachePolicy)cachePolicy {
NSAssert(cachePolicy != kPFCachePolicyCacheThenNetwork, @"Can not use BFTask with kPFCachePolicyCacheThenNetwork because the callback my be executed more than once. Use a signature that accepts a block instead");
BFTaskCompletionSource *tcs = [BFTaskCompletionSource taskCompletionSource];
[self callFunctionInBackground:function withParameters:parameters cachePolicy:cachePolicy block:^(id object, NSError *error) {
if(error)
[tcs setError:error];
else
[tcs setResult:object];
}];
return tcs.task;
}


+ (void)callFunctionInBackground:(NSString*)function withParameters:(NSDictionary*)parameters cachePolicy:(PFCachePolicy)cachePolicy block:(PFIdResultBlock)block
{
NSParameterAssert(block);
Expand Down