diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index becfb83ab3..f8d9aeab24 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -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]; diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index 8f602bce86..231daa19ba 100644 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -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)]; } @@ -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) { @@ -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; @@ -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]; } } diff --git a/AFNetworking/AFURLResponseSerialization.m b/AFNetworking/AFURLResponseSerialization.m index b8e4d1c953..6fcf1fd681 100644 --- a/AFNetworking/AFURLResponseSerialization.m +++ b/AFNetworking/AFURLResponseSerialization.m @@ -68,11 +68,11 @@ static id AFJSONObjectByRemovingKeysWithNullValues(id JSONObject, NSJSONReadingO } else if ([JSONObject isKindOfClass:[NSDictionary class]]) { NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithDictionary:JSONObject]; for (id 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); } } diff --git a/Example/Classes/Controllers/GlobalTimelineViewController.m b/Example/Classes/Controllers/GlobalTimelineViewController.m index 3529ff4869..c70f1c0420 100644 --- a/Example/Classes/Controllers/GlobalTimelineViewController.m +++ b/Example/Classes/Controllers/GlobalTimelineViewController.m @@ -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; } @@ -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 diff --git a/Tests/Tests/1.0 Tests/AFHTTPClientTests.m b/Tests/Tests/1.0 Tests/AFHTTPClientTests.m index c43fe9eebc..5325bc055a 100644 --- a/Tests/Tests/1.0 Tests/AFHTTPClientTests.m +++ b/Tests/Tests/1.0 Tests/AFHTTPClientTests.m @@ -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 { @@ -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]); diff --git a/Tests/Tests/AFSecurityPolicyTests.m b/Tests/Tests/AFSecurityPolicyTests.m index 8251a7c1fa..a9582640c2 100644 --- a/Tests/Tests/AFSecurityPolicyTests.m +++ b/Tests/Tests/AFSecurityPolicyTests.m @@ -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;