Skip to content

Commit ab13cc2

Browse files
committed
Merge pull request #549 from ParsePlatform/nlutsenko.public.modern
Update all public classes to modern Obj-C syntax.
2 parents f38c9ed + 756969b commit ab13cc2

File tree

12 files changed

+84
-87
lines changed

12 files changed

+84
-87
lines changed

Parse/PFACL.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ - (void)setUnresolvedReadAccess:(BOOL)allowed forUser:(PFUser *)user {
270270
- (void)setReadAccess:(BOOL)allowed forUser:(PFUser *)user {
271271
NSString *objectId = user.objectId;
272272
if (!objectId) {
273-
if ([user isLazy]) {
273+
if (user.isLazy) {
274274
[self setUnresolvedReadAccess:allowed forUser:user];
275275
return;
276276
}
@@ -296,7 +296,7 @@ - (void)setUnresolvedWriteAccess:(BOOL)allowed forUser:(PFUser *)user {
296296
- (void)setWriteAccess:(BOOL)allowed forUser:(PFUser *)user {
297297
NSString *objectId = user.objectId;
298298
if (!objectId) {
299-
if ([user isLazy]) {
299+
if (user.isLazy) {
300300
[self setUnresolvedWriteAccess:allowed forUser:user];
301301
return;
302302
}
@@ -336,7 +336,7 @@ - (BOOL)isEqual:(id)object {
336336
}
337337

338338
- (NSUInteger)hash {
339-
return [self.state hash] ^ [unresolvedUser hash];
339+
return self.state.hash ^ unresolvedUser.hash;
340340
}
341341

342342
///--------------------------------------

Parse/PFConfig.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ - (id)objectForKeyedSubscript:(NSString *)keyedSubscript {
9696
#pragma mark Equality Testing
9797

9898
- (NSUInteger)hash {
99-
return [_parametersDictionary hash];
99+
return _parametersDictionary.hash;
100100
}
101101

102102
- (BOOL)isEqual:(id)object {
103103
if ([object isKindOfClass:[PFConfig class]]) {
104104
PFConfig *other = object;
105105

106106
// Compare pointers first, to account for nil dictionary
107-
return self.parametersDictionary == other.parametersDictionary ||
108-
[self.parametersDictionary isEqual:other.parametersDictionary];
107+
return (self.parametersDictionary == other.parametersDictionary ||
108+
[self.parametersDictionary isEqual:other.parametersDictionary]);
109109
}
110110

111111
return NO;

Parse/PFFile.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,24 @@ + (instancetype)fileWithName:(NSString *)name contentsAtPath:(NSString *)path er
7575
BOOL directory = NO;
7676

7777
if (![fileManager fileExistsAtPath:path isDirectory:&directory] || directory) {
78-
NSString *message = [NSString stringWithFormat:@"Failed to create PFFile at path '%@': "
79-
"file does not exist.", path];
78+
NSString *message = [NSString stringWithFormat:@"Failed to create PFFile at path '%@': file does not exist.", path];
8079
if (error) {
8180
*error = [NSError errorWithDomain:NSCocoaErrorDomain
8281
code:NSFileNoSuchFileError
83-
userInfo:@{ NSLocalizedDescriptionKey: message }];
82+
userInfo:@{ NSLocalizedDescriptionKey : message }];
8483
}
8584
return nil;
8685
}
8786

8887
NSDictionary *attributes = [fileManager attributesOfItemAtPath:path error:nil];
8988
unsigned long long length = [attributes[NSFileSize] unsignedLongValue];
9089
if (length > PFFileMaxFileSize) {
91-
NSString *message = [NSString stringWithFormat:@"Failed to create PFFile at path '%@': "
92-
"file is larger than %lluMB.", path, (PFFileMaxFileSize >> 20)];
90+
NSString *message = [NSString stringWithFormat:@"Failed to create PFFile at path '%@': file is larger than %lluMB.",
91+
path, (PFFileMaxFileSize >> 20)];
9392
if (error) {
9493
*error = [NSError errorWithDomain:NSCocoaErrorDomain
9594
code:NSFileReadTooLargeError
96-
userInfo:@{ NSLocalizedDescriptionKey: message }];
95+
userInfo:@{ NSLocalizedDescriptionKey : message }];
9796
}
9897
return nil;
9998
}
@@ -123,18 +122,18 @@ + (instancetype)fileWithName:(NSString *)name
123122
if (error) {
124123
*error = [NSError errorWithDomain:NSCocoaErrorDomain
125124
code:NSFileNoSuchFileError
126-
userInfo:@{ NSLocalizedDescriptionKey: message }];
125+
userInfo:@{ NSLocalizedDescriptionKey : message }];
127126
}
128127
return nil;
129128
}
130129

131-
if ([data length] > PFFileMaxFileSize) {
132-
NSString *message = [NSString stringWithFormat:@"Failed to create PFFile with data: "
133-
"data is larger than %lluMB.", (PFFileMaxFileSize >> 20)];
130+
if (data.length > PFFileMaxFileSize) {
131+
NSString *message = [NSString stringWithFormat:@"Failed to create PFFile with data: data is larger than %lluMB.",
132+
(PFFileMaxFileSize >> 20)];
134133
if (error) {
135134
*error = [NSError errorWithDomain:NSCocoaErrorDomain
136135
code:NSFileReadTooLargeError
137-
userInfo:@{ NSLocalizedDescriptionKey: message }];
136+
userInfo:@{ NSLocalizedDescriptionKey : message }];
138137
}
139138
return nil;
140139
}
@@ -249,7 +248,7 @@ - (void)getDataInBackgroundWithTarget:(id)target selector:(SEL)selector {
249248
}];
250249
}
251250

252-
- (BFTask PF_GENERIC(NSString *) *)getFilePathInBackground {
251+
- (BFTask PF_GENERIC(NSString *)*)getFilePathInBackground {
253252
return [self getFilePathInBackgroundWithProgressBlock:nil];
254253
}
255254

Parse/PFGeoPoint.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ + (void)geoPointForCurrentLocationInBackground:(PFGeoPointResultBlock)resultBloc
4848
return;
4949
}
5050

51-
void(^locationHandler)(CLLocation *, NSError *) = ^(CLLocation *location, NSError *error) {
51+
void (^locationHandler)(CLLocation *, NSError *) = ^(CLLocation *location, NSError *error) {
5252
PFGeoPoint *newGeoPoint = [PFGeoPoint geoPointWithLocation:location];
5353
resultBlock(newGeoPoint, error);
5454
};
@@ -75,15 +75,14 @@ - (double)distanceInRadiansTo:(PFGeoPoint *)point {
7575
double d2r = M_PI / 180.0; // radian conversion factor
7676
double lat1rad = self.latitude * d2r;
7777
double long1rad = self.longitude * d2r;
78-
double lat2rad = [point latitude] * d2r;
79-
double long2rad = [point longitude] * d2r;
78+
double lat2rad = point.latitude * d2r;
79+
double long2rad = point.longitude * d2r;
8080
double deltaLat = lat1rad - lat2rad;
8181
double deltaLong = long1rad - long2rad;
8282
double sinDeltaLatDiv2 = sin(deltaLat / 2.);
8383
double sinDeltaLongDiv2 = sin(deltaLong / 2.);
8484
// Square of half the straight line chord distance between both points. [0.0, 1.0]
85-
double a = sinDeltaLatDiv2 * sinDeltaLatDiv2
86-
+ cos(lat1rad) * cos(lat2rad) * sinDeltaLongDiv2 * sinDeltaLongDiv2;
85+
double a = sinDeltaLatDiv2 * sinDeltaLatDiv2 + cos(lat1rad) * cos(lat2rad) * sinDeltaLongDiv2 * sinDeltaLongDiv2;
8786
a = fmin(1.0, a);
8887
return 2. * asin(sqrt(a));
8988
}

Parse/PFInstallation.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ - (void)_updateBadgeFromDevice {
276276
}
277277

278278
- (void)_updateVersionInfoFromDevice {
279-
NSDictionary *appInfo = [[NSBundle mainBundle] infoDictionary];
279+
NSDictionary *appInfo = [NSBundle mainBundle].infoDictionary;
280280
NSString *appName = appInfo[(__bridge NSString *)kCFBundleNameKey];
281281
NSString *appVersion = appInfo[(__bridge NSString *)kCFBundleVersionKey];
282282
NSString *appIdentifier = appInfo[(__bridge NSString *)kCFBundleIdentifierKey];

Parse/PFObject.m

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ + (BFTask *)_deepSaveAsync:(id)object withCurrentUser:(PFUser *)currentUser sess
401401
// TODO: (nlutsenko) Get rid of this once we allow localIds in batches.
402402
NSArray *remaining = [uniqueObjects allObjects];
403403
NSMutableArray *finished = [NSMutableArray array];
404-
while ([remaining count] > 0) {
404+
while (remaining.count > 0) {
405405
// Partition the objects into two sets: those that can be save immediately,
406406
// and those that rely on other objects to be created first.
407407
NSMutableArray *current = [NSMutableArray array];
@@ -429,7 +429,7 @@ + (BFTask *)_deepSaveAsync:(id)object withCurrentUser:(PFUser *)currentUser sess
429429
// This has to happen separately from everything else because there [PFUser save]
430430
// is special-cased to work for lazy users, but new users can't be created by
431431
// PFMultiCommand's regular save.
432-
if ([currentUser isLazy] && [current containsObject:currentUser]) {
432+
if (currentUser.isLazy && [current containsObject:currentUser]) {
433433
task = [task continueAsyncWithSuccessBlock:^id(BFTask *task) {
434434
return [currentUser saveInBackground];
435435
}];
@@ -447,12 +447,12 @@ + (BFTask *)_deepSaveAsync:(id)object withCurrentUser:(PFUser *)currentUser sess
447447
// and execute them concurrently with a wrapper task for all of them.
448448
NSArray *objectBatches = [PFInternalUtils arrayBySplittingArray:current
449449
withMaximumComponentsPerSegment:PFRESTObjectBatchCommandSubcommandsLimit];
450-
NSMutableArray *tasks = [NSMutableArray arrayWithCapacity:[objectBatches count]];
450+
NSMutableArray *tasks = [NSMutableArray arrayWithCapacity:objectBatches.count];
451451

452452
for (NSArray *objectBatch in objectBatches) {
453453
BFTask *batchTask = [self _enqueue:^BFTask *(BFTask *toAwait) {
454454
return [toAwait continueAsyncWithBlock:^id(BFTask *task) {
455-
NSMutableArray *commands = [NSMutableArray arrayWithCapacity:[objectBatch count]];
455+
NSMutableArray *commands = [NSMutableArray arrayWithCapacity:objectBatch.count];
456456
for (PFObject *object in objectBatch) {
457457
PFRESTCommand *command = nil;
458458
@synchronized ([object lock]) {
@@ -472,7 +472,7 @@ + (BFTask *)_deepSaveAsync:(id)object withCurrentUser:(PFUser *)currentUser sess
472472
continueAsyncWithBlock:^id(BFTask *commandRunnerTask) {
473473
NSArray *results = [commandRunnerTask.result result];
474474

475-
NSMutableArray *handleSaveTasks = [NSMutableArray arrayWithCapacity:[objectBatch count]];
475+
NSMutableArray *handleSaveTasks = [NSMutableArray arrayWithCapacity:objectBatch.count];
476476

477477
__block NSError *error = task.error;
478478
[objectBatch enumerateObjectsUsingBlock:^(PFObject *object, NSUInteger idx, BOOL *stop) {
@@ -565,10 +565,10 @@ + (BFTask *)_enqueueSaveEventuallyChildrenOfObject:(PFObject *)object
565565
// Remove object from the queue of objects to save as this method should only save children.
566566
[uniqueObjects removeObject:object];
567567

568-
NSArray *remaining = [uniqueObjects allObjects];
568+
NSArray *remaining = uniqueObjects.allObjects;
569569
NSMutableArray *finished = [NSMutableArray array];
570570
NSMutableArray *enqueueTasks = [NSMutableArray array];
571-
while ([remaining count] > 0) {
571+
while (remaining.count > 0) {
572572
// Partition the objects into two sets: those that can be save immediately,
573573
// and those that rely on other objects to be created first.
574574
NSMutableArray *current = [NSMutableArray array];
@@ -600,7 +600,7 @@ + (BFTask *)_enqueueSaveEventuallyChildrenOfObject:(PFObject *)object
600600
// Unfortunately, ACLs with lazy users still cannot be saved, because the ACL does
601601
// does not get updated after the user save completes.
602602
// TODO: (nlutsenko) Make the ACL update after the user is saved.
603-
if ([currentUser isLazy] && [current containsObject:currentUser]) {
603+
if (currentUser.isLazy && [current containsObject:currentUser]) {
604604
[enqueueTasks addObject:[currentUser _enqueueSaveEventuallyWithChildren:NO]];
605605
[finished addObject:currentUser];
606606
[current removeObject:currentUser];
@@ -941,7 +941,7 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
941941
if ([key isEqualToString:PFObjectOperationsRESTKey]) {
942942
PFOperationSet *remoteOperationSet = nil;
943943
NSArray *operations = (NSArray *)obj;
944-
if ([operations count] > 0) {
944+
if (operations.count > 0) {
945945
// Add and enqueue any saveEventually operations, roll forward any other
946946
// operations sets (operations sets here are generally failed/incomplete saves).
947947
PFOperationSet *current = nil;
@@ -957,7 +957,7 @@ - (void)mergeFromRESTDictionary:(NSDictionary *)object withDecoder:(PFDecoder *)
957957
// Check if queue already contains this operation set and discard it if does
958958
if (![self _containsOperationSet:operationSet]) {
959959
// Insert the `saveEventually` operationSet before the last operation set at all times.
960-
NSUInteger index = ([operationSetQueue count] == 0 ? 0 : [operationSetQueue count] - 1);
960+
NSUInteger index = (operationSetQueue.count == 0 ? 0 : operationSetQueue.count - 1);
961961
[operationSetQueue insertObject:operationSet atIndex:index];
962962
[self _enqueueSaveEventuallyOperationAsync:operationSet];
963963
}
@@ -1187,7 +1187,7 @@ - (BOOL)_containsOperationSet:(PFOperationSet *)operationSet {
11871187
*/
11881188
- (PFOperationSet *)unsavedChanges {
11891189
@synchronized (lock) {
1190-
return [operationSetQueue lastObject];
1190+
return operationSetQueue.lastObject;
11911191
}
11921192
}
11931193

@@ -1207,7 +1207,7 @@ - (BOOL)_hasChanges {
12071207
- (BOOL)_hasOutstandingOperations {
12081208
@synchronized (lock) {
12091209
// > 1 since 1 is unsaved changes.
1210-
return [operationSetQueue count] > 1;
1210+
return operationSetQueue.count > 1;
12111211
}
12121212
}
12131213

@@ -1254,9 +1254,9 @@ - (void)removeOldKeysAfterFetch:(NSDictionary *)result {
12541254
PFMutableObjectState *state = [self._state mutableCopy];
12551255

12561256
NSMutableDictionary *removedDictionary = [NSMutableDictionary dictionaryWithDictionary:state.serverData];
1257-
[removedDictionary removeObjectsForKeys:[result allKeys]];
1257+
[removedDictionary removeObjectsForKeys:result.allKeys];
12581258

1259-
NSArray *removedKeys = [removedDictionary allKeys];
1259+
NSArray *removedKeys = removedDictionary.allKeys;
12601260
[state removeServerDataObjectsForKeys:removedKeys];
12611261
[_availableKeys minusSet:[NSSet setWithArray:removedKeys]];
12621262

@@ -1321,7 +1321,7 @@ - (void)_mergeFromServerWithResult:(NSDictionary *)result decoder:(PFDecoder *)d
13211321
state.updatedAt = state.createdAt;
13221322
}
13231323
self._state = state;
1324-
[_availableKeys addObjectsFromArray:[result allKeys]];
1324+
[_availableKeys addObjectsFromArray:result.allKeys];
13251325

13261326
dirty = NO;
13271327
}
@@ -1969,7 +1969,7 @@ - (BOOL)isDirty {
19691969

19701970
- (BOOL)isDirtyForKey:(NSString *)key {
19711971
@synchronized (lock) {
1972-
return [self unsavedChanges][key] != nil;
1972+
return ([self unsavedChanges][key] != nil);
19731973
}
19741974
}
19751975

@@ -2200,12 +2200,12 @@ - (void)removeObjectForKey:(NSString *)key {
22002200
- (void)revert {
22012201
@synchronized (self.lock) {
22022202
if (self.dirty) {
2203-
NSMutableSet *persistentKeys = [NSMutableSet setWithArray:[self._state.serverData allKeys]];
2203+
NSMutableSet *persistentKeys = [NSMutableSet setWithArray:self._state.serverData.allKeys];
22042204

22052205
PFOperationSet *unsavedChanges = [self unsavedChanges];
22062206
for (PFOperationSet *operationSet in operationSetQueue) {
22072207
if (operationSet != unsavedChanges) {
2208-
[persistentKeys addObjectsFromArray:[operationSet.keyEnumerator allObjects]];
2208+
[persistentKeys addObjectsFromArray:operationSet.keyEnumerator.allObjects];
22092209
}
22102210
}
22112211

@@ -2301,7 +2301,7 @@ - (void)setValue:(id)value forUndefinedKey:(NSString *)key {
23012301

23022302
- (NSArray *)allKeys {
23032303
@synchronized (lock) {
2304-
return [_estimatedData allKeys];
2304+
return _estimatedData.allKeys;
23052305
}
23062306
}
23072307

@@ -2321,7 +2321,7 @@ - (NSString *)description {
23212321
- (NSString *)_recursiveDescription {
23222322
@synchronized (lock) {
23232323
return [NSString stringWithFormat:@"%@ %@",
2324-
[self _flatDescription], [_estimatedData.dictionaryRepresentation description]];
2324+
[self _flatDescription], _estimatedData.dictionaryRepresentation.description];
23252325
}
23262326
}
23272327

@@ -2435,13 +2435,13 @@ + (BOOL)resolveInstanceMethod:(SEL)sel {
24352435
}
24362436

24372437
// Convert the method signature *back* into a objc type string (sidenote, why isn't this a built in?).
2438-
NSMutableString *typeString = [NSMutableString stringWithFormat:@"%s", [signature methodReturnType]];
2439-
for (NSUInteger argumentIndex = 0; argumentIndex < [signature numberOfArguments]; argumentIndex++) {
2438+
NSMutableString *typeString = [NSMutableString stringWithFormat:@"%s", signature.methodReturnType];
2439+
for (NSUInteger argumentIndex = 0; argumentIndex < signature.numberOfArguments; argumentIndex++) {
24402440
[typeString appendFormat:@"%s", [signature getArgumentTypeAtIndex:argumentIndex]];
24412441
}
24422442

24432443
// TODO: (richardross) Support stret return here (will need to introspect the method signature to do so).
2444-
class_addMethod(self, sel, _objc_msgForward, [typeString UTF8String]);
2444+
class_addMethod(self, sel, _objc_msgForward, typeString.UTF8String);
24452445

24462446
return YES;
24472447
}

0 commit comments

Comments
 (0)