Skip to content

Commit

Permalink
Enable more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Apr 8, 2016
1 parent 19e4aef commit 885e0a4
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 30 deletions.
42 changes: 40 additions & 2 deletions AFNetworking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1215,14 +1215,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_ASSIGN_ENUM = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
Expand All @@ -1240,10 +1248,22 @@
);
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES;
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_MISSING_PARENTHESES = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VALUE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.9;
Expand All @@ -1267,14 +1287,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_ASSIGN_ENUM = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
Expand All @@ -1286,10 +1314,22 @@
GCC_NO_COMMON_BLOCKS = YES;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES;
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES;
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES;
GCC_WARN_MISSING_PARENTHESES = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_SIGN_COMPARE = YES;
GCC_WARN_STRICT_SELECTOR_MATCH = YES;
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VALUE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.9;
Expand All @@ -1314,7 +1354,6 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_WARN_SHADOW = YES;
INFOPLIST_FILE = ./Framework/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
Expand All @@ -1336,7 +1375,6 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
GCC_WARN_SHADOW = YES;
INFOPLIST_FILE = ./Framework/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
Expand Down
14 changes: 7 additions & 7 deletions Tests/Tests/AFAutoPurgingImageCacheTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ - (void)testThatMemoryUsageDecreasesWhenRemovingImage {
#pragma mark - Purging
- (void)testThatImagesArePurgedWhenCapcityIsReached {
UInt64 imageSize = 1020000;
NSInteger numberOfImages = 10;
NSInteger numberOfImagesAfterPurge = 6;
UInt64 numberOfImages = 10;
UInt64 numberOfImagesAfterPurge = 6;
self.cache = [[AFAutoPurgingImageCache alloc] initWithMemoryCapacity:numberOfImages * imageSize preferredMemoryCapacity:numberOfImagesAfterPurge * imageSize];
NSInteger index = 1;
NSUInteger index = 1;
while (YES) {
NSString * identifier = [NSString stringWithFormat:@"image-%ld",(long)index];
[self.cache addImage:self.testImage withIdentifier:identifier];
Expand All @@ -203,10 +203,10 @@ - (void)testThatImagesArePurgedWhenCapcityIsReached {

- (void)testThatPrioritizedImagesWithOldestLastAccessDatesAreRemovedDuringPurge {
UInt64 imageSize = 1020000;
NSInteger numberOfImages = 10;
NSInteger numberOfImagesAfterPurge = 6;
UInt64 numberOfImages = 10;
UInt64 numberOfImagesAfterPurge = 6;
self.cache = [[AFAutoPurgingImageCache alloc] initWithMemoryCapacity:numberOfImages * imageSize preferredMemoryCapacity:numberOfImagesAfterPurge * imageSize];
for (NSInteger index = 0; index < numberOfImages; index ++) {
for (NSUInteger index = 0; index < numberOfImages; index ++) {
NSString * identifier = [NSString stringWithFormat:@"image-%ld",(long)index];
[self.cache addImage:self.testImage withIdentifier:identifier];
}
Expand All @@ -219,7 +219,7 @@ - (void)testThatPrioritizedImagesWithOldestLastAccessDatesAreRemovedDuringPurge
UInt64 postPurgeMemoryUsage = self.cache.memoryUsage;
XCTAssertTrue(postPurgeMemoryUsage < prePurgeMemoryUsage);

for (NSInteger index = 0; index <= numberOfImages ; index++) {
for (NSUInteger index = 0; index <= numberOfImages ; index++) {
NSString * identifier = [NSString stringWithFormat:@"image-%ld",(long)index];
UIImage *cachedImage = [self.cache imageWithIdentifier:identifier];
if (index == 0 || index >= 6) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Tests/AFCompoundResponseSerializerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (void)testCompoundSerializerProperlySerializesResponse {
AFJSONResponseSerializer *jsonSerializer = [AFJSONResponseSerializer serializer];
AFCompoundResponseSerializer *compoundSerializer = [AFCompoundResponseSerializer compoundSerializerWithResponseSerializers:@[imageSerializer, jsonSerializer]];

NSData *data = [NSJSONSerialization dataWithJSONObject:@{@"key":@"value"} options:0 error:nil];
NSData *data = [NSJSONSerialization dataWithJSONObject:@{@"key":@"value"} options:(NSJSONWritingOptions)0 error:nil];
NSURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://test.com"]
statusCode:200
HTTPVersion:@"1.1"
Expand Down
8 changes: 4 additions & 4 deletions Tests/Tests/AFHTTPResponseSerializationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (void)setUp {
- (void)testThatAFHTTPResponseSerializationHandlesAll2XXCodes {
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
[indexSet enumerateIndexesUsingBlock:^(NSUInteger statusCode, BOOL *stop) {
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:statusCode HTTPVersion:@"1.1" headerFields:@{@"Content-Type": @"text/html"}];
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:(NSInteger)statusCode HTTPVersion:@"1.1" headerFields:@{@"Content-Type": @"text/html"}];

XCTAssert([self.responseSerializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %@ should be acceptable", @(statusCode));

Expand All @@ -54,7 +54,7 @@ - (void)testThatAFHTTPResponseSerializationSucceedsWith205WithNoResponseContentT
NSInteger statusCode = 205;
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:statusCode HTTPVersion:@"1.1" headerFields:@{}];

XCTAssert([self.responseSerializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %@ should be acceptable", @(statusCode));
XCTAssert([self.responseSerializer.acceptableStatusCodes containsIndex:(NSUInteger)statusCode], @"Status code %@ should be acceptable", @(statusCode));

NSError *error = nil;
self.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
Expand All @@ -69,7 +69,7 @@ - (void)testThatAFHTTPResponseSerializationFailsWith205WithNoResponseContentType
NSInteger statusCode = 205;
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:statusCode HTTPVersion:@"1.1" headerFields:@{}];

XCTAssert([self.responseSerializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %@ should be acceptable", @(statusCode));
XCTAssert([self.responseSerializer.acceptableStatusCodes containsIndex:(NSUInteger)statusCode], @"Status code %@ should be acceptable", @(statusCode));

NSError *error = nil;
self.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
Expand All @@ -81,7 +81,7 @@ - (void)testThatAFHTTPResponseSerializationFailsWith205WithNoResponseContentType
- (void)testThatAFHTTPResponseSerializationFailsAll4XX5XXStatusCodes {
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(400, 200)];
[indexSet enumerateIndexesUsingBlock:^(NSUInteger statusCode, BOOL *stop) {
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:statusCode HTTPVersion:@"1.1" headerFields:@{@"Content-Type": @"text/html"}];
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:(NSInteger)statusCode HTTPVersion:@"1.1" headerFields:@{@"Content-Type": @"text/html"}];

XCTAssert(![self.responseSerializer.acceptableStatusCodes containsIndex:statusCode], @"Status code %@ should not be acceptable", @(statusCode));

Expand Down
8 changes: 4 additions & 4 deletions Tests/Tests/AFHTTPSessionManagerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ - (void)testThatRedirectBlockIsCalledWhen302IsEncountered {

XCTestExpectation *expectation = [self expectationWithDescription:@"Request should succeed"];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:self.baseURL]];
NSURLSessionDataTask *task = [self.manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSURLRequest *redirectRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/redirect/1" relativeToURL:self.baseURL]];
NSURLSessionDataTask *redirectTask = [self.manager dataTaskWithRequest:redirectRequest completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
blockError = error;
[expectation fulfill];
}];
Expand All @@ -108,11 +108,11 @@ - (void)testThatRedirectBlockIsCalledWhen302IsEncountered {
return request;
}];

[task resume];
[redirectTask resume];

[self waitForExpectationsWithTimeout:10.0 handler:nil];

XCTAssertTrue(task.state == NSURLSessionTaskStateCompleted);
XCTAssertTrue(redirectTask.state == NSURLSessionTaskStateCompleted);
XCTAssertNil(blockError);
XCTAssertTrue(success);
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Tests/AFImageDownloaderTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ - (void)testThatSimultaneouslyRequestsForTheSameAssetReceiveSameResponse {
- (void)testThatImageBehindRedirectCanBeDownloaded {
XCTestExpectation *expectation = [self expectationWithDescription:@"image download should succeed"];
NSURL *redirectURL = [self.jpegRequest URL];
NSURLRequest *request = [NSURLRequest requestWithURL:redirectURL];
NSURLRequest *downloadRequest = [NSURLRequest requestWithURL:redirectURL];

__block NSHTTPURLResponse *urlResponse = nil;
__block UIImage *responseImage = nil;

[self.downloader
downloadImageForURLRequest:request
downloadImageForURLRequest:downloadRequest
success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, UIImage * _Nonnull responseObject) {
urlResponse = response;
responseImage = responseObject;
Expand Down Expand Up @@ -421,11 +421,11 @@ - (void)testThatItAlwaysCallsTheSuccessHandlerOnTheMainQueue {

- (void)testThatItAlwaysCallsTheFailureHandlerOnTheMainQueue {
NSURL *url = [NSURL URLWithString:@"https://httpbin.org/status/404"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLRequest *notFoundRequest = [NSURLRequest requestWithURL:url];
XCTestExpectation *expectation = [self expectationWithDescription:@"image download should fail"];
__block BOOL failureIsOnMainThread = false;
[self.downloader
downloadImageForURLRequest:request
downloadImageForURLRequest:notFoundRequest
success:nil
failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {
failureIsOnMainThread = [[NSThread currentThread] isMainThread];
Expand Down
4 changes: 2 additions & 2 deletions Tests/Tests/AFJSONSerializationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#import "AFURLResponseSerialization.h"

static NSData * AFJSONTestData() {
return [NSJSONSerialization dataWithJSONObject:@{@"foo": @"bar"} options:0 error:nil];
return [NSJSONSerialization dataWithJSONObject:@{@"foo": @"bar"} options:(NSJSONWritingOptions)0 error:nil];
}

#pragma mark -
Expand Down Expand Up @@ -155,7 +155,7 @@ - (void)testThatJSONRemovesKeysWithNullValues {
self.responseSerializer.removesKeysWithNullValues = YES;
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] initWithURL:self.baseURL statusCode:200 HTTPVersion:@"1.1" headerFields:@{@"Content-Type":@"text/json"}];
NSData *data = [NSJSONSerialization dataWithJSONObject:@{@"key":@"value",@"nullkey":[NSNull null],@"array":@[@{@"subnullkey":[NSNull null]}]}
options:0
options:(NSJSONWritingOptions)0
error:nil];

NSError *error = nil;
Expand Down
4 changes: 2 additions & 2 deletions Tests/Tests/AFSecurityPolicyTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ - (void)testPolicyWithPublicKeyPinningModeHasHTTPBinOrgPinnedCertificate {
return [data isEqualToData:certData];
}];

XCTAssertEqual(set.count, 1, @"HTTPBin.org certificate not found in the default certificates");
XCTAssertEqual(set.count, 1U, @"HTTPBin.org certificate not found in the default certificates");
}

#pragma mark Positive Server Trust Evaluation Tests
Expand Down Expand Up @@ -349,7 +349,7 @@ - (void)testPolicyWithCertificatePinningModeHasHTTPBinOrgPinnedCertificate {
return [data isEqualToData:certData];
}];

XCTAssertEqual(set.count, 1, @"HTTPBin.org certificate not found in the default certificates");
XCTAssertEqual(set.count, 1U, @"HTTPBin.org certificate not found in the default certificates");
}

#pragma mark Positive Server Trust Evaluation Tests
Expand Down
5 changes: 3 additions & 2 deletions UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {

if (task) {
if (task.state != NSURLSessionTaskStateCompleted) {
UIActivityIndicatorView *activityIndicatorView = self.activityIndicatorView;
if (task.state == NSURLSessionTaskStateRunning) {
[self.activityIndicatorView startAnimating];
[activityIndicatorView startAnimating];
} else {
[self.activityIndicatorView stopAnimating];
[activityIndicatorView stopAnimating];
}

[notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingTaskDidResumeNotification object:task];
Expand Down
5 changes: 3 additions & 2 deletions UIKit+AFNetworking/UIRefreshControl+AFNetworking.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task {
[notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];

if (task) {
UIRefreshControl *refreshControl = self.refreshControl;
if (task.state == NSURLSessionTaskStateRunning) {
[self.refreshControl beginRefreshing];
[refreshControl beginRefreshing];

[notificationCenter addObserver:self selector:@selector(af_beginRefreshing) name:AFNetworkingTaskDidResumeNotification object:task];
[notificationCenter addObserver:self selector:@selector(af_endRefreshing) name:AFNetworkingTaskDidCompleteNotification object:task];
[notificationCenter addObserver:self selector:@selector(af_endRefreshing) name:AFNetworkingTaskDidSuspendNotification object:task];
} else {
[self.refreshControl endRefreshing];
[refreshControl endRefreshing];
}
}
}
Expand Down

0 comments on commit 885e0a4

Please sign in to comment.