Skip to content

Commit ed59b66

Browse files
committed
Merge pull request #682 from ParsePlatform/nlutsenko.synchronous
Split synchronous methods of all public classes into categories.
2 parents 6a496fb + f71c316 commit ed59b66

24 files changed

+1634
-1221
lines changed

Parse.podspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Pod::Spec.new do |s|
3030
'Parse/Internal/PFMemoryEventuallyQueue.{h,m}'
3131
s.tvos.exclude_files = 'Parse/PFNetworkActivityIndicatorManager.{h,m}',
3232
'Parse/PFPush.{h,m}',
33+
'Parse/PFPush+Synchronous.{h,m}',
3334
'Parse/PFPush+Deprecated.{h,m}',
3435
'Parse/PFInstallation.{h,m}',
3536
'Parse/Internal/PFAlertView.{h,m}',
@@ -43,6 +44,7 @@ Pod::Spec.new do |s|
4344
'Parse/PFProduct.{h,m}',
4445
'Parse/PFPurchase.{h,m}',
4546
'Parse/PFPush.{h,m}',
47+
'Parse/PFPush+Synchronous.{h,m}',
4648
'Parse/PFPush+Deprecated.{h,m}',
4749
'Parse/PFInstallation.{h,m}',
4850
'Parse/Internal/PFAlertView.{h,m}',

Parse.xcodeproj/project.pbxproj

Lines changed: 66 additions & 0 deletions
Large diffs are not rendered by default.

Parse/PFCloud+Synchronous.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <Parse/PFCloud.h>
11+
#import <Parse/PFConstants.h>
12+
13+
NS_ASSUME_NONNULL_BEGIN
14+
15+
/**
16+
This category lists all methods of `PFCloud` class that are synchronous, but have asynchronous counterpart,
17+
Calling one of these synchronous methods could potentially block the current thread for a large amount of time,
18+
since it might be fetching from network or saving/loading data from disk.
19+
*/
20+
@interface PFCloud (Synchronous)
21+
22+
/**
23+
Calls the given cloud function *synchronously* with the parameters provided.
24+
25+
@param function The function name to call.
26+
@param parameters The parameters to send to the function.
27+
28+
@return The response from the cloud function.
29+
*/
30+
+ (nullable id)callFunction:(NSString *)function withParameters:(nullable NSDictionary *)parameters PF_SWIFT_UNAVAILABLE;
31+
32+
/**
33+
Calls the given cloud function *synchronously* with the parameters provided and
34+
sets the error if there is one.
35+
36+
@param function The function name to call.
37+
@param parameters The parameters to send to the function.
38+
@param error Pointer to an `NSError` that will be set if necessary.
39+
40+
@return The response from the cloud function.
41+
This result could be a `NSDictionary`, an `NSArray`, `NSNumber` or `NSString`.
42+
*/
43+
+ (nullable id)callFunction:(NSString *)function withParameters:(nullable NSDictionary *)parameters error:(NSError **)error;
44+
45+
@end
46+
47+
NS_ASSUME_NONNULL_END

Parse/PFCloud.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,6 @@ NS_ASSUME_NONNULL_BEGIN
2020
*/
2121
@interface PFCloud : NSObject
2222

23-
/**
24-
Calls the given cloud function *synchronously* with the parameters provided.
25-
26-
@param function The function name to call.
27-
@param parameters The parameters to send to the function.
28-
29-
@return The response from the cloud function.
30-
*/
31-
+ (nullable id)callFunction:(NSString *)function withParameters:(nullable NSDictionary *)parameters PF_SWIFT_UNAVAILABLE;
32-
33-
/**
34-
Calls the given cloud function *synchronously* with the parameters provided and
35-
sets the error if there is one.
36-
37-
@param function The function name to call.
38-
@param parameters The parameters to send to the function.
39-
@param error Pointer to an `NSError` that will be set if necessary.
40-
41-
@return The response from the cloud function.
42-
This result could be a `NSDictionary`, an `NSArray`, `NSNumber` or `NSString`.
43-
*/
44-
+ (nullable id)callFunction:(NSString *)function
45-
withParameters:(nullable NSDictionary *)parameters
46-
error:(NSError **)error;
47-
4823
/**
4924
Calls the given cloud function *asynchronously* with the parameters provided.
5025

Parse/PFCloud.m

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ @implementation PFCloud
2222
#pragma mark - Public
2323
///--------------------------------------
2424

25-
+ (id)callFunction:(NSString *)function withParameters:(NSDictionary *)parameters {
26-
return [self callFunction:function withParameters:parameters error:nil];
27-
}
28-
29-
+ (id)callFunction:(NSString *)function withParameters:(NSDictionary *)parameters error:(NSError **)error {
30-
return [[self callFunctionInBackground:function withParameters:parameters] waitForResult:error];
31-
}
32-
3325
+ (BFTask *)callFunctionInBackground:(NSString *)functionName withParameters:(NSDictionary *)parameters {
3426
return [[PFUser _getCurrentUserSessionTokenAsync] continueWithBlock:^id(BFTask *task) {
3527
NSString *sessionToken = task.result;
@@ -48,6 +40,22 @@ + (void)callFunctionInBackground:(NSString *)function
4840

4941
@end
5042

43+
///--------------------------------------
44+
#pragma mark - Synchronous
45+
///--------------------------------------
46+
47+
@implementation PFCloud (Synchronous)
48+
49+
+ (id)callFunction:(NSString *)function withParameters:(NSDictionary *)parameters {
50+
return [self callFunction:function withParameters:parameters error:nil];
51+
}
52+
53+
+ (id)callFunction:(NSString *)function withParameters:(NSDictionary *)parameters error:(NSError **)error {
54+
return [[self callFunctionInBackground:function withParameters:parameters] waitForResult:error];
55+
}
56+
57+
@end
58+
5159
///--------------------------------------
5260
#pragma mark - Deprecated
5361
///--------------------------------------

Parse/PFConfig+Synchronous.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <Parse/PFConfig.h>
11+
#import <Parse/PFConstants.h>
12+
13+
NS_ASSUME_NONNULL_BEGIN
14+
15+
/**
16+
This category lists all methods of `PFConfig` class that are synchronous, but have asynchronous counterpart,
17+
Calling one of these synchronous methods could potentially block the current thread for a large amount of time,
18+
since it might be fetching from network or saving/loading data from disk.
19+
*/
20+
@interface PFConfig (Synchronous)
21+
22+
///--------------------------------------
23+
/// @name Retrieving Config
24+
///--------------------------------------
25+
26+
/**
27+
Gets the `PFConfig` object *synchronously* from the server.
28+
29+
@return Instance of `PFConfig` if the operation succeeded, otherwise `nil`.
30+
*/
31+
+ (nullable PFConfig *)getConfig PF_SWIFT_UNAVAILABLE;
32+
33+
/**
34+
Gets the `PFConfig` object *synchronously* from the server and sets an error if it occurs.
35+
36+
@param error Pointer to an `NSError` that will be set if necessary.
37+
38+
@return Instance of PFConfig if the operation succeeded, otherwise `nil`.
39+
*/
40+
+ (nullable PFConfig *)getConfig:(NSError **)error;
41+
42+
@end
43+
44+
NS_ASSUME_NONNULL_END

Parse/PFConfig.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,6 @@ typedef void(^PFConfigResultBlock)(PFConfig *__nullable config, NSError *__nulla
4242
/// @name Retrieving Config
4343
///--------------------------------------
4444

45-
/**
46-
Gets the `PFConfig` object *synchronously* from the server.
47-
48-
@return Instance of `PFConfig` if the operation succeeded, otherwise `nil`.
49-
*/
50-
+ (nullable PFConfig *)getConfig PF_SWIFT_UNAVAILABLE;
51-
52-
/**
53-
Gets the `PFConfig` object *synchronously* from the server and sets an error if it occurs.
54-
55-
@param error Pointer to an `NSError` that will be set if necessary.
56-
57-
@return Instance of PFConfig if the operation succeeded, otherwise `nil`.
58-
*/
59-
+ (nullable PFConfig *)getConfig:(NSError **)error;
60-
6145
/**
6246
Gets the `PFConfig` *asynchronously* and sets it as a result of a task.
6347

Parse/PFConfig.m

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ - (instancetype)initWithFetchedConfig:(NSDictionary *)resultDictionary {
6161
#pragma mark - Fetch
6262
///--------------------------------------
6363

64-
+ (PFConfig *)getConfig {
65-
return [self getConfig:nil];
66-
}
67-
68-
+ (PFConfig *)getConfig:(NSError **)error {
69-
return [[self getConfigInBackground] waitForResult:error];
70-
}
71-
7264
+ (BFTask *)getConfigInBackground {
7365
PFCurrentUserController *controller = [Parse _currentManager].coreManager.currentUserController;
7466
return [[controller getCurrentUserSessionTokenAsync] continueWithBlock:^id(BFTask *task) {
@@ -112,3 +104,21 @@ - (BOOL)isEqual:(id)object {
112104
}
113105

114106
@end
107+
108+
///--------------------------------------
109+
#pragma mark - Synchronous
110+
///--------------------------------------
111+
112+
@implementation PFConfig (Synchronous)
113+
114+
#pragma mark Retrieving Config
115+
116+
+ (PFConfig *)getConfig {
117+
return [self getConfig:nil];
118+
}
119+
120+
+ (PFConfig *)getConfig:(NSError **)error {
121+
return [[self getConfigInBackground] waitForResult:error];
122+
}
123+
124+
@end

Parse/PFFile+Synchronous.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright (c) 2015-present, Parse, LLC.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <Parse/PFConstants.h>
11+
#import <Parse/PFFile.h>
12+
13+
NS_ASSUME_NONNULL_BEGIN
14+
15+
/**
16+
This category lists all methods of `PFFile` class that are synchronous, but have asynchronous counterpart,
17+
Calling one of these synchronous methods could potentially block the current thread for a large amount of time,
18+
since it might be fetching from network or saving/loading data from disk.
19+
*/
20+
@interface PFFile (Synchronous)
21+
22+
///--------------------------------------
23+
/// @name Storing Data with Parse
24+
///--------------------------------------
25+
26+
/**
27+
Saves the file *synchronously*.
28+
29+
@return Returns whether the save succeeded.
30+
*/
31+
- (BOOL)save PF_SWIFT_UNAVAILABLE;
32+
33+
/**
34+
Saves the file *synchronously* and sets an error if it occurs.
35+
36+
@param error Pointer to an `NSError` that will be set if necessary.
37+
38+
@return Returns whether the save succeeded.
39+
*/
40+
- (BOOL)save:(NSError **)error;
41+
42+
///--------------------------------------
43+
/// @name Getting Data from Parse
44+
///--------------------------------------
45+
46+
/**
47+
Whether the data is available in memory or needs to be downloaded.
48+
*/
49+
@property (nonatomic, assign, readonly, getter=isDataAvailable) BOOL dataAvailable;
50+
51+
/**
52+
*Synchronously* gets the data from cache if available or fetches its contents from the network.
53+
54+
@return The `NSData` object containing file data. Returns `nil` if there was an error in fetching.
55+
*/
56+
- (nullable NSData *)getData PF_SWIFT_UNAVAILABLE;
57+
58+
/**
59+
*Synchronously* gets the data from cache if available or fetches its contents from the network.
60+
Sets an error if it occurs.
61+
62+
@param error Pointer to an `NSError` that will be set if necessary.
63+
64+
@return The `NSData` object containing file data. Returns `nil` if there was an error in fetching.
65+
*/
66+
- (nullable NSData *)getData:(NSError **)error;
67+
68+
/**
69+
This method is like `-getData` but avoids ever holding the entire `PFFile` contents in memory at once.
70+
71+
This can help applications with many large files avoid memory warnings.
72+
73+
@return A stream containing the data. Returns `nil` if there was an error in fetching.
74+
*/
75+
- (nullable NSInputStream *)getDataStream PF_SWIFT_UNAVAILABLE;
76+
77+
/**
78+
This method is like `-getData` but avoids ever holding the entire `PFFile` contents in memory at once.
79+
80+
@param error Pointer to an `NSError` that will be set if necessary.
81+
82+
@return A stream containing the data. Returns nil if there was an error in
83+
fetching.
84+
*/
85+
- (nullable NSInputStream *)getDataStream:(NSError **)error;
86+
87+
@end
88+
89+
NS_ASSUME_NONNULL_END

Parse/PFFile.h

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,6 @@ NS_ASSUME_NONNULL_BEGIN
151151
/// @name Storing Data with Parse
152152
///--------------------------------------
153153

154-
/**
155-
Saves the file *synchronously*.
156-
157-
@return Returns whether the save succeeded.
158-
*/
159-
- (BOOL)save PF_SWIFT_UNAVAILABLE;
160-
161-
/**
162-
Saves the file *synchronously* and sets an error if it occurs.
163-
164-
@param error Pointer to an `NSError` that will be set if necessary.
165-
166-
@return Returns whether the save succeeded.
167-
*/
168-
- (BOOL)save:(NSError **)error;
169-
170154
/**
171155
Saves the file *asynchronously*.
172156
@@ -211,41 +195,6 @@ NS_ASSUME_NONNULL_BEGIN
211195
*/
212196
@property (nonatomic, assign, readonly, getter=isDataAvailable) BOOL dataAvailable;
213197

214-
/**
215-
*Synchronously* gets the data from cache if available or fetches its contents from the network.
216-
217-
@return The `NSData` object containing file data. Returns `nil` if there was an error in fetching.
218-
*/
219-
- (nullable NSData *)getData PF_SWIFT_UNAVAILABLE;
220-
221-
/**
222-
This method is like `-getData` but avoids ever holding the entire `PFFile` contents in memory at once.
223-
224-
This can help applications with many large files avoid memory warnings.
225-
226-
@return A stream containing the data. Returns `nil` if there was an error in fetching.
227-
*/
228-
- (nullable NSInputStream *)getDataStream PF_SWIFT_UNAVAILABLE;
229-
230-
/**
231-
*Synchronously* gets the data from cache if available or fetches its contents from the network.
232-
Sets an error if it occurs.
233-
234-
@param error Pointer to an `NSError` that will be set if necessary.
235-
236-
@return The `NSData` object containing file data. Returns `nil` if there was an error in fetching.
237-
*/
238-
- (nullable NSData *)getData:(NSError **)error;
239-
240-
/**
241-
This method is like `-getData` but avoids ever holding the entire `PFFile` contents in memory at once.
242-
243-
@param error Pointer to an `NSError` that will be set if necessary.
244-
245-
@return A stream containing the data. Returns nil if there was an error in
246-
fetching.
247-
*/
248-
- (nullable NSInputStream *)getDataStream:(NSError **)error;
249198

250199
/**
251200
This method is like `-getData` but it fetches asynchronously to avoid blocking the current thread.

0 commit comments

Comments
 (0)