Skip to content

Commit

Permalink
Minor changes to support modern Objective-C syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattshedlick committed Apr 28, 2015
1 parent 9a5043d commit a04a4ff
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion AFNetworking/AFURLConnectionOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ - (void)cancel {
- (void)cancelConnection {
NSDictionary *userInfo = nil;
if ([self.request URL]) {
userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
userInfo = @{NSURLErrorFailingURLErrorKey : [self.request URL]};
}
NSError *error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo];

Expand Down
10 changes: 5 additions & 5 deletions AFNetworking/AFURLRequestSerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding
NSDictionary *dictionary = value;
// Sort dictionary keys to ensure consistent ordering in query string, which is important when deserializing potentially ambiguous sequences, such as an array of dictionaries
for (id nestedKey in [dictionary.allKeys sortedArrayUsingDescriptors:@[ sortDescriptor ]]) {
id nestedValue = [dictionary objectForKey:nestedKey];
id nestedValue = dictionary[nestedKey];
if (nestedValue) {
[mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)];
}
Expand Down Expand Up @@ -218,9 +218,9 @@ - (instancetype)init {
#pragma clang diagnostic ignored "-Wgnu"
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
// User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]];
userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]];
#endif
#pragma clang diagnostic pop
if (userAgent) {
Expand Down Expand Up @@ -730,7 +730,7 @@ - (BOOL)appendPartWithFileURL:(NSURL *)fileURL
bodyPart.headers = mutableHeaders;
bodyPart.boundary = self.boundary;
bodyPart.body = fileURL;
bodyPart.bodyContentLength = [[fileAttributes objectForKey:NSFileSize] unsignedLongLongValue];
bodyPart.bodyContentLength = [fileAttributes[NSFileSize] unsignedLongLongValue];
[self.bodyStream appendHTTPBodyPart:bodyPart];

return YES;
Expand Down Expand Up @@ -873,7 +873,7 @@ - (void)setInitialAndFinalBoundaries {
bodyPart.hasFinalBoundary = NO;
}

[[self.HTTPBodyParts objectAtIndex:0] setHasInitialBoundary:YES];
[[self.HTTPBodyParts firstObject] setHasInitialBoundary:YES];
[[self.HTTPBodyParts lastObject] setHasFinalBoundary:YES];
}
}
Expand Down
4 changes: 2 additions & 2 deletions AFNetworking/AFURLResponseSerialization.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ static id AFJSONObjectByRemovingKeysWithNullValues(id JSONObject, NSJSONReadingO
} else if ([JSONObject isKindOfClass:[NSDictionary class]]) {
NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithDictionary:JSONObject];
for (id <NSCopying> key in [(NSDictionary *)JSONObject allKeys]) {
id value = [(NSDictionary *)JSONObject objectForKey:key];
id value = (NSDictionary *)JSONObject[key];
if (!value || [value isEqual:[NSNull null]]) {
[mutableDictionary removeObjectForKey:key];
} else if ([value isKindOfClass:[NSArray class]] || [value isKindOfClass:[NSDictionary class]]) {
[mutableDictionary setObject:AFJSONObjectByRemovingKeysWithNullValues(value, readingOptions) forKey:key];
mutableDictionary[key] = AFJSONObjectByRemovingKeysWithNullValues(value, readingOptions);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Example/Classes/Controllers/GlobalTimelineViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView
cell = [[PostTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

cell.post = [self.posts objectAtIndex:(NSUInteger)indexPath.row];
cell.post = self.posts[(NSUInteger)indexPath.row];

return cell;
}
Expand All @@ -93,7 +93,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView
- (CGFloat)tableView:(__unused UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [PostTableViewCell heightForCellWithPost:[self.posts objectAtIndex:(NSUInteger)indexPath.row]];
return [PostTableViewCell heightForCellWithPost:self.posts[(NSUInteger)indexPath.row]];
}

- (void)tableView:(UITableView *)tableView
Expand Down
8 changes: 4 additions & 4 deletions Tests/Tests/1.0 Tests/AFHTTPClientTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ - (void)testThatEnqueueBatchOfHTTPRequestOperationsConstructsOperationsWithAppro
expect(operations).notTo.beNil();
expect(operations).to.haveCountOf(2);

expect([[operations objectAtIndex:0] class]).to.equal([AFJSONRequestOperation class]);
expect([[operations objectAtIndex:1] class]).to.equal([AFImageRequestOperation class]);
expect([operations[0] class]).to.equal([AFJSONRequestOperation class]);
expect([operations[1] class]).to.equal([AFImageRequestOperation class]);
}

- (void)testThatEnqueueBatchOfHTTPRequestOperationsEnqueuesOperationsInTheCorrectOrder {
Expand Down Expand Up @@ -313,8 +313,8 @@ - (void)testThatEnqueueBatchOfHTTPRequestOperationsEnqueuesOperationsInTheCorrec

expect(operations).to.haveCountOf(2);

expect([operations objectAtIndex:0]).to.equal(firstOperation);
expect([operations objectAtIndex:1]).to.equal(secondOperation);
expect(operations[0]).to.equal(firstOperation);
expect(operations[1]).to.equal(secondOperation);

expect(batchedOperation).notTo.beNil();
expect(batchedOperation).to.beKindOf([NSBlockOperation class]);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests/AFSecurityPolicyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static SecCertificateRef AFUTSelfSignedCertificateWithDNSNameDomain() {
}

static SecTrustRef AFUTTrustWithCertificate(SecCertificateRef certificate) {
NSArray *certs = [NSArray arrayWithObject:(__bridge id)(certificate)];
NSArray *certs = @[(__bridge id)(certificate)];

SecPolicyRef policy = SecPolicyCreateBasicX509();
SecTrustRef trust = NULL;
Expand Down

0 comments on commit a04a4ff

Please sign in to comment.