Skip to content

Commit 93bd9eb

Browse files
committed
Merge pull request #689 from ParsePlatform/nlutsenko.modernize
Use property accessors via dot-syntax where possible instead of method invocations.
2 parents 7c0aa86 + d20f83c commit 93bd9eb

File tree

64 files changed

+208
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+208
-209
lines changed

Parse/Internal/Analytics/Utilities/PFAnalyticsUtilities.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ + (NSString *)md5DigestFromPushPayload:(id)payload {
1717
if (!payload || payload == [NSNull null]) {
1818
payload = @"";
1919
} else if ([payload isKindOfClass:[NSDictionary class]]) {
20-
NSDictionary *dict = payload;
21-
NSArray *keys = [[dict allKeys] sortedArrayUsingSelector:@selector(compare:)];
22-
NSMutableArray *components = [NSMutableArray arrayWithCapacity:[dict count] * 2];
20+
NSDictionary *dictionary = payload;
21+
NSArray *keys = [dictionary.allKeys sortedArrayUsingSelector:@selector(compare:)];
22+
23+
NSMutableArray *components = [NSMutableArray arrayWithCapacity:dictionary.count * 2];
2324
[keys enumerateObjectsUsingBlock:^(id key, NSUInteger idx, BOOL *stop) {
2425
[components addObject:key];
2526

2627
// alert[@"loc-args"] can be an NSArray
27-
id value = dict[key];
28+
id value = dictionary[key];
2829
if ([value isKindOfClass:[NSArray class]]) {
2930
value = [value componentsJoinedByString:@""];
3031
}

Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ + (instancetype)constructorWithDataSource:(id<PFInstallationIdentifierStoreProvi
101101

102102
//TODO (nlutsenko): Check for error here.
103103
NSNumber *fileSize = [PFInternalUtils fileSizeOfFileAtPath:contentFilePath error:nil];
104-
[request setValue:[fileSize stringValue] forHTTPHeaderField:PFHTTPRequestHeaderNameContentLength];
104+
[request setValue:fileSize.stringValue forHTTPHeaderField:PFHTTPRequestHeaderNameContentLength];
105105

106106
return request;
107107
}];

Parse/Internal/Commands/CommandRunner/URLSession/PFURLSessionCommandRunner.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ - (BFTask *)_performCommandRunningBlock:(nonnull id (^)())block
239239
return task;
240240
}
241241

242-
if ([[task.error userInfo][@"temporary"] boolValue] && attempts > 1) {
242+
if ([task.error.userInfo[@"temporary"] boolValue] && attempts > 1) {
243243
PFLogError(PFLoggingTagCommon,
244244
@"Network connection failed. Making attempt %lu after sleeping for %f seconds.",
245245
(unsigned long)(_retryAttempts - attempts + 1), (double)delay);

Parse/Internal/Commands/CommandRunner/URLSession/Session/TaskDelegate/PFURLSessionDataTaskDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ - (void)_openDataOutputStream {
104104
}
105105

106106
- (void)_writeDataOutputStreamData:(NSData *)data {
107-
NSInteger length = [data length];
107+
NSInteger length = data.length;
108108
while (YES) {
109109
NSInteger bytesWritten = 0;
110110
if ([self.dataOutputStream hasSpaceAvailable]) {

Parse/Internal/Commands/CommandRunner/URLSession/Session/TaskDelegate/PFURLSessionJSONDataTaskDelegate.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ - (void)_taskDidFinish {
5555
errorDictionary[NSUnderlyingErrorKey] = self.error;
5656
errorDictionary[@"temporary"] = @(self.response.statusCode >= 500 || self.response.statusCode < 400);
5757

58-
NSString *description = [self.error localizedDescription] ?: [self.error localizedFailureReason];
58+
NSString *description = self.error.localizedDescription ?: self.error.localizedFailureReason;
5959
if (description) {
6060
errorDictionary[@"error"] = description;
6161
}

Parse/Internal/Commands/PFRESTCommand.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ - (void)maybeChangeServerOperation {
149149
if (objectId) {
150150
self.localId = nil;
151151

152-
NSArray *components = [self.httpPath pathComponents];
153-
if ([components count] == 2) {
152+
NSArray *components = self.httpPath.pathComponents;
153+
if (components.count == 2) {
154154
self.httpPath = [NSString pathWithComponents:[components arrayByAddingObject:objectId]];
155155
}
156156

Parse/Internal/Commands/PFRESTObjectBatchCommand.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ @implementation PFRESTObjectBatchCommand
2020
+ (nonnull instancetype)batchCommandWithCommands:(nonnull NSArray PF_GENERIC(PFRESTCommand *)*)commands
2121
sessionToken:(nullable NSString *)sessionToken
2222
serverURL:(nonnull NSURL *)serverURL {
23-
PFParameterAssert([commands count] <= PFRESTObjectBatchCommandSubcommandsLimit,
23+
PFParameterAssert(commands.count <= PFRESTObjectBatchCommandSubcommandsLimit,
2424
@"Max of %d commands are allowed in a single batch command",
2525
(int)PFRESTObjectBatchCommandSubcommandsLimit);
2626

27-
NSMutableArray *requests = [NSMutableArray arrayWithCapacity:[commands count]];
27+
NSMutableArray *requests = [NSMutableArray arrayWithCapacity:commands.count];
2828
for (PFRESTCommand *command in commands) {
29-
NSURL *commandURL = [PFURLConstructor URLFromAbsoluteString:[serverURL absoluteString]
29+
NSURL *commandURL = [PFURLConstructor URLFromAbsoluteString:serverURL.absoluteString
3030
path:command.httpPath
3131
query:nil];
3232
NSMutableDictionary *requestDictionary = [@{ @"method" : command.httpMethod,

Parse/Internal/Commands/PFRESTPushCommand.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ + (instancetype)sendPushCommandWithPushState:(PFPushState *)state
2828
parameters[@"where"] = queryParameters[@"where"];
2929
} else {
3030
if (state.channels) {
31-
parameters[@"channels"] = [state.channels allObjects];
31+
parameters[@"channels"] = state.channels.allObjects;
3232
}
3333
}
3434

3535
// If there are no conditions set, then push to everyone by specifying empty query conditions.
36-
if ([parameters count] == 0) {
36+
if (parameters.count == 0) {
3737
parameters[@"where"] = @{};
3838
}
3939

Parse/Internal/Commands/PFRESTQueryCommand.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ + (NSDictionary *)findCommandParametersWithOrder:(NSString *)order
103103
tracingEnabled:(BOOL)trace {
104104
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
105105

106-
if ([order length]) {
106+
if (order.length) {
107107
parameters[@"order"] = order;
108108
}
109109
if (selectedKeys) {
110110
NSArray *sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES selector:@selector(compare:)] ];
111111
NSArray *keysArray = [selectedKeys sortedArrayUsingDescriptors:sortDescriptors];
112112
parameters[@"keys"] = [keysArray componentsJoinedByString:@","];
113113
}
114-
if ([includedKeys count] > 0) {
114+
if (includedKeys.count > 0) {
115115
NSArray *sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES selector:@selector(compare:)] ];
116116
NSArray *keysArray = [includedKeys sortedArrayUsingDescriptors:sortDescriptors];
117117
parameters[@"include"] = [keysArray componentsJoinedByString:@","];
@@ -130,7 +130,7 @@ + (NSDictionary *)findCommandParametersWithOrder:(NSString *)order
130130
parameters[key] = obj;
131131
}];
132132

133-
if ([conditions count] > 0) {
133+
if (conditions.count > 0) {
134134
NSMutableDictionary *whereData = [[NSMutableDictionary alloc] init];
135135
[conditions enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
136136
if ([key isEqualToString:@"$or"]) {
@@ -154,7 +154,7 @@ + (NSDictionary *)findCommandParametersWithOrder:(NSString *)order
154154
tracingEnabled:NO];
155155

156156
queryDict = queryDict[@"where"];
157-
if ([queryDict count] > 0) {
157+
if (queryDict.count > 0) {
158158
[newArray addObject:queryDict];
159159
} else {
160160
[newArray addObject:@{}];

Parse/Internal/FieldOperation/PFFieldOperation.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ - (instancetype)initWithObjects:(NSArray *)array {
238238
self = [super init];
239239
if (!self) return nil;
240240

241-
_objects = [[NSSet setWithArray:array] allObjects];
241+
_objects = [NSSet setWithArray:array].allObjects;
242242

243243
return self;
244244
}
@@ -294,7 +294,7 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key {
294294
if (index == NSNotFound) {
295295
[newValue addObject:objectToAdd];
296296
} else {
297-
[newValue replaceObjectAtIndex:index withObject:objectToAdd];
297+
newValue[index] = objectToAdd;
298298
}
299299
} else if (![newValue containsObject:objectToAdd]) {
300300
[newValue addObject:objectToAdd];
@@ -372,7 +372,7 @@ - (id)applyToValue:(id)oldValue forKey:(NSString *)key {
372372
return ([obj isKindOfClass:[PFObject class]] &&
373373
[[obj objectId] isEqualToString:[objectToRemove objectId]]);
374374
}];
375-
if ([indexes count] != 0) {
375+
if (indexes.count != 0) {
376376
[newValue removeObjectsAtIndexes:indexes];
377377
}
378378
}
@@ -405,7 +405,7 @@ - (instancetype)init {
405405
+ (instancetype)addRelationToObjects:(NSArray *)targets {
406406
PFRelationOperation *op = [[self alloc] init];
407407
if (targets.count > 0) {
408-
op.targetClass = [[targets firstObject] parseClassName];
408+
op.targetClass = [targets.firstObject parseClassName];
409409
}
410410

411411
for (PFObject *target in targets) {

0 commit comments

Comments
 (0)