From db9a5884b5719ee310b8baabaef108fd037901b0 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Mon, 30 Mar 2015 12:44:43 +0200 Subject: [PATCH 1/3] Added NSError category for Reactive programming --- Podfile | 2 +- RACAFNetworking.xcodeproj/project.pbxproj | 63 +++++++++++++++ RACAFNetworking/NSError+AFNetworking.h | 39 +++++++++ RACAFNetworking/NSError+AFNetworking.m | 96 +++++++++++++++++++++++ RACAFNetworking/RACAFNetworking.h | 2 +- 5 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 RACAFNetworking/NSError+AFNetworking.h create mode 100644 RACAFNetworking/NSError+AFNetworking.m diff --git a/Podfile b/Podfile index 6dce258..0f45fd9 100644 --- a/Podfile +++ b/Podfile @@ -4,4 +4,4 @@ podspec :path => "./AFNetworking-RACExtensions.podspec" pod 'Specta', '~> 0.1.11' pod 'Expecta', '~> 0.2.3' -link_with ['Reactive AFNetworking Example', 'RAFNetworking Tests'] +#link_with ['Reactive AFNetworking Example', 'RAFNetworking Tests'] diff --git a/RACAFNetworking.xcodeproj/project.pbxproj b/RACAFNetworking.xcodeproj/project.pbxproj index ac80b46..804fc27 100644 --- a/RACAFNetworking.xcodeproj/project.pbxproj +++ b/RACAFNetworking.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 38BDA07E1AC95EFB00598012 /* NSError+AFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 38BDA07C1AC95EFB00598012 /* NSError+AFNetworking.h */; }; + 38BDA07F1AC95EFB00598012 /* NSError+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 38BDA07D1AC95EFB00598012 /* NSError+AFNetworking.m */; }; 84DA97D7196C9FEA0064A552 /* RACAFNetworking.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DA97D6196C9FEA0064A552 /* RACAFNetworking.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84DA97DD196C9FEA0064A552 /* RACAFNetworking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84DA97D1196C9FEA0064A552 /* RACAFNetworking.framework */; }; 84DA97F5196CA0430064A552 /* AFHTTPRequestOperationManager+RACSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DA97ED196CA0430064A552 /* AFHTTPRequestOperationManager+RACSupport.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -95,6 +97,7 @@ 84DA995A196CAD4C0064A552 /* AFURLSessionManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DA9810196CA05D0064A552 /* AFURLSessionManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84DA995B196CAD4D0064A552 /* AFHTTPRequestOperationManager+RAFMocking.h in Headers */ = {isa = PBXBuildFile; fileRef = 84DA98DA196CA4E00064A552 /* AFHTTPRequestOperationManager+RAFMocking.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84DA995C196CAE5A0064A552 /* libReactiveCocoa-iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 84DA987A196CA1520064A552 /* libReactiveCocoa-iOS.a */; }; + D810CE5FB1F8A49119746F1F /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E73B8343A69B25B12DBC8F5 /* libPods.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -274,6 +277,9 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 38BDA07C1AC95EFB00598012 /* NSError+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+AFNetworking.h"; sourceTree = ""; }; + 38BDA07D1AC95EFB00598012 /* NSError+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+AFNetworking.m"; sourceTree = ""; }; + 6E73B8343A69B25B12DBC8F5 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 84DA97D1196C9FEA0064A552 /* RACAFNetworking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RACAFNetworking.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84DA97D5196C9FEA0064A552 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84DA97D6196C9FEA0064A552 /* RACAFNetworking.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RACAFNetworking.h; sourceTree = ""; }; @@ -351,6 +357,7 @@ 84DA990D196CA6210064A552 /* SystemConfiguration.framework in Frameworks */, 84DA990B196CA6160064A552 /* Cocoa.framework in Frameworks */, 84DA9887196CA15D0064A552 /* ReactiveCocoa.framework in Frameworks */, + D810CE5FB1F8A49119746F1F /* libPods.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -393,6 +400,8 @@ 84DA97D3196C9FEA0064A552 /* RACAFNetworking */, 84DA97E0196C9FEA0064A552 /* RACAFNetworkingTests */, 84DA97D2196C9FEA0064A552 /* Products */, + EA219C96B04AD746C68A20C9 /* Pods */, + 999C4C432BF5F82FE8B0BAF2 /* Frameworks */, ); sourceTree = ""; }; @@ -452,6 +461,8 @@ 84DA97FD196CA0470064A552 /* Classes */ = { isa = PBXGroup; children = ( + 38BDA07C1AC95EFB00598012 /* NSError+AFNetworking.h */, + 38BDA07D1AC95EFB00598012 /* NSError+AFNetworking.m */, 84DA97ED196CA0430064A552 /* AFHTTPRequestOperationManager+RACSupport.h */, 84DA97EE196CA0430064A552 /* AFHTTPRequestOperationManager+RACSupport.m */, 84DA97EF196CA0430064A552 /* AFHTTPSessionManager+RACSupport.h */, @@ -649,6 +660,21 @@ name = Frameworks; sourceTree = ""; }; + 999C4C432BF5F82FE8B0BAF2 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 6E73B8343A69B25B12DBC8F5 /* libPods.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + EA219C96B04AD746C68A20C9 /* Pods */ = { + isa = PBXGroup; + children = ( + ); + name = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -657,6 +683,7 @@ buildActionMask = 2147483647; files = ( 84DA9823196CA05D0064A552 /* AFURLSessionManager.h in Headers */, + 38BDA07E1AC95EFB00598012 /* NSError+AFNetworking.h in Headers */, 84DA981F196CA05D0064A552 /* AFURLRequestSerialization.h in Headers */, 84DA981B196CA05D0064A552 /* AFSecurityPolicy.h in Headers */, 84DA97F9196CA0430064A552 /* AFURLConnectionOperation+RACSupport.h in Headers */, @@ -727,10 +754,12 @@ isa = PBXNativeTarget; buildConfigurationList = 84DA97E7196C9FEA0064A552 /* Build configuration list for PBXNativeTarget "RACAFNetworking" */; buildPhases = ( + 368AF30A4FB5523CDAFC10AD /* Check Pods Manifest.lock */, 84DA97CC196C9FEA0064A552 /* Sources */, 84DA97CD196C9FEA0064A552 /* Frameworks */, 84DA97CE196C9FEA0064A552 /* Headers */, 84DA97CF196C9FEA0064A552 /* Resources */, + A00922B8173C96F4A1A5D13A /* Copy Pods Resources */, ); buildRules = ( ); @@ -990,6 +1019,39 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 368AF30A4FB5523CDAFC10AD /* Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; + A00922B8173C96F4A1A5D13A /* Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 84DA97CC196C9FEA0064A552 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -999,6 +1061,7 @@ 84DA981C196CA05D0064A552 /* AFSecurityPolicy.m in Sources */, 84DA97F6196CA0430064A552 /* AFHTTPRequestOperationManager+RACSupport.m in Sources */, 84DA9815196CA05D0064A552 /* AFHTTPRequestOperationManager.m in Sources */, + 38BDA07F1AC95EFB00598012 /* NSError+AFNetworking.m in Sources */, 84DA981E196CA05D0064A552 /* AFURLConnectionOperation.m in Sources */, 84DA9813196CA05D0064A552 /* AFHTTPRequestOperation.m in Sources */, 84DA97FA196CA0430064A552 /* AFURLConnectionOperation+RACSupport.m in Sources */, diff --git a/RACAFNetworking/NSError+AFNetworking.h b/RACAFNetworking/NSError+AFNetworking.h new file mode 100644 index 0000000..96f7d93 --- /dev/null +++ b/RACAFNetworking/NSError+AFNetworking.h @@ -0,0 +1,39 @@ +// NSError+AFNetworking.h +// +// Copyright (c) 2013-2015 AFNetworking (http://afnetworking.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import + +@interface NSError (AFNetworking) + +/*! + * HTTP Status Code that was returned from network + */ +@property (nonatomic, readonly) NSInteger af_networkStatusCode; + +@property (nonatomic, readonly) NSData *af_responseData; +@property (nonatomic, readonly) NSString *af_responseString; +@property (nonatomic, readonly) NSString *af_requestURL; + +@property (nonatomic, readonly) NSURLResponse *af_response; +@property (nonatomic, readonly) NSURLRequest *af_request; + +@end \ No newline at end of file diff --git a/RACAFNetworking/NSError+AFNetworking.m b/RACAFNetworking/NSError+AFNetworking.m new file mode 100644 index 0000000..af366f5 --- /dev/null +++ b/RACAFNetworking/NSError+AFNetworking.m @@ -0,0 +1,96 @@ +// NSError+AFNetworking.m +// +// Copyright (c) 2013-2015 AFNetworking (http://afnetworking.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +#import "NSError+AFNetworking.h" +#import "AFURLRequestSerialization.h" + +@implementation NSError (AFNetworking) + +- (NSInteger)af_networkStatusCode +{ + NSURLResponse* response = [self af_response]; + + if ([response isKindOfClass:[NSHTTPURLResponse class]]) + { + NSHTTPURLResponse* urlResponse = (NSHTTPURLResponse *)response; + + return urlResponse.statusCode; + } + + return 0; +} + +- (NSURLRequest *)af_request +{ + return [self af_objectInUserInfo:AFNetworkingOperationFailingURLRequestErrorKey withError:self]; +} + +- (NSURLResponse *)af_response +{ + return [self objectInUserInfo:AFNetworkingOperationFailingURLResponseErrorKey withError:self]; +} + +- (NSData *)af_responseData +{ + return [self af_objectInUserInfo:AFNetworkingOperationFailingURLResponseDataErrorKey withError:self]; +} + +- (NSString *)af_responseString +{ + return [[NSString alloc] initWithData:[self af_objectInUserInfo:AFNetworkingOperationFailingURLResponseDataErrorKey withError:self] encoding:NSUTF8StringEncoding]; +} + +- (NSString *)af_requestURL +{ + NSURLResponse* response = [self af_response]; + + if ([response isKindOfClass:[NSHTTPURLResponse class]]) + { + NSHTTPURLResponse* urlResponse = (NSHTTPURLResponse *)response; + + return urlResponse.URL.absoluteString; + } + else + { + return (self.originalError.userInfo[NSURLErrorFailingURLStringErrorKey]) ? self.originalError.userInfo[NSURLErrorFailingURLStringErrorKey] : nil; + } +} + +#pragma mark - Helpers + +- (id)af_objectInUserInfo:(NSString *)key withError:(NSError *)error +{ + if (error.userInfo[key]) + { + return error.userInfo[key]; + } + + // + // Check for underlying error + // + + NSError* underlyingError = error.userInfo[NSUnderlyingErrorKey]; + + return (underlyingError.userInfo[key]) ? underlyingError.userInfo[key] : nil; +} + +@end diff --git a/RACAFNetworking/RACAFNetworking.h b/RACAFNetworking/RACAFNetworking.h index 3a1687f..f46b5bc 100644 --- a/RACAFNetworking/RACAFNetworking.h +++ b/RACAFNetworking/RACAFNetworking.h @@ -9,4 +9,4 @@ #import "AFHTTPRequestOperationManager+RACSupport.h" #import "AFURLConnectionOperation+RACSupport.h" #import "AFHTTPSessionManager+RACSupport.h" - +#import "NSError+AFNetworking.h" From 46c60da76b60ba0623cede27bd6b033f9d3159ef Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 31 Mar 2015 19:11:53 +0200 Subject: [PATCH 2/3] Refactoring NSError category --- ...Networking.h => NSError+RACAFNetworking.h} | 36 ++++++---- ...Networking.m => NSError+RACAFNetworking.m} | 65 ++++++++----------- RACAFNetworking/RACAFNetworking.h | 2 +- 3 files changed, 52 insertions(+), 51 deletions(-) rename RACAFNetworking/{NSError+AFNetworking.h => NSError+RACAFNetworking.h} (58%) rename RACAFNetworking/{NSError+AFNetworking.m => NSError+RACAFNetworking.m} (52%) diff --git a/RACAFNetworking/NSError+AFNetworking.h b/RACAFNetworking/NSError+RACAFNetworking.h similarity index 58% rename from RACAFNetworking/NSError+AFNetworking.h rename to RACAFNetworking/NSError+RACAFNetworking.h index 96f7d93..7dc0cba 100644 --- a/RACAFNetworking/NSError+AFNetworking.h +++ b/RACAFNetworking/NSError+RACAFNetworking.h @@ -1,6 +1,9 @@ -// NSError+AFNetworking.h // -// Copyright (c) 2013-2015 AFNetworking (http://afnetworking.com) +// NSError+AFNetworking.m +// +// The MIT License (MIT) +// +// Copyright (c) 2015 Dal Rupnik (https://github.com/legoless) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -19,21 +22,28 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +// #import -@interface NSError (AFNetworking) +@interface NSError (RACAFNetworking) + +/// HTTP Status Code that was returned from network +@property (nonatomic, readonly) NSInteger rac_networkStatusCode; + +/// Response data that was returned from network +@property (nonatomic, readonly) NSData *rac_responseData; + +/// Response string allocated from response data in UTF8 format +@property (nonatomic, readonly) NSString *rac_responseString; -/*! - * HTTP Status Code that was returned from network - */ -@property (nonatomic, readonly) NSInteger af_networkStatusCode; +/// Request URL +@property (nonatomic, readonly) NSString *rac_requestURL; -@property (nonatomic, readonly) NSData *af_responseData; -@property (nonatomic, readonly) NSString *af_responseString; -@property (nonatomic, readonly) NSString *af_requestURL; +/// NSURLResponse object with response details +@property (nonatomic, readonly) NSURLResponse *rac_response; -@property (nonatomic, readonly) NSURLResponse *af_response; -@property (nonatomic, readonly) NSURLRequest *af_request; +/// NSURLRequest object with request information +@property (nonatomic, readonly) NSURLRequest *rac_request; -@end \ No newline at end of file +@end diff --git a/RACAFNetworking/NSError+AFNetworking.m b/RACAFNetworking/NSError+RACAFNetworking.m similarity index 52% rename from RACAFNetworking/NSError+AFNetworking.m rename to RACAFNetworking/NSError+RACAFNetworking.m index af366f5..7e003c8 100644 --- a/RACAFNetworking/NSError+AFNetworking.m +++ b/RACAFNetworking/NSError+RACAFNetworking.m @@ -1,6 +1,9 @@ -// NSError+AFNetworking.m // -// Copyright (c) 2013-2015 AFNetworking (http://afnetworking.com) +// NSError+RACAFNetworking.m +// +// The MIT License (MIT) +// +// Copyright (c) 2015 Dal Rupnik (https://github.com/legoless) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -19,19 +22,19 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +// -#import "NSError+AFNetworking.h" +#import "NSError+RACAFNetworking.h" #import "AFURLRequestSerialization.h" -@implementation NSError (AFNetworking) +@implementation NSError (RACAFNetworking) -- (NSInteger)af_networkStatusCode -{ - NSURLResponse* response = [self af_response]; +- (NSInteger)rac_networkStatusCode { + NSURLResponse *response = [self rac_response]; if ([response isKindOfClass:[NSHTTPURLResponse class]]) { - NSHTTPURLResponse* urlResponse = (NSHTTPURLResponse *)response; + NSHTTPURLResponse *urlResponse = (NSHTTPURLResponse *)response; return urlResponse.statusCode; } @@ -39,58 +42,46 @@ - (NSInteger)af_networkStatusCode return 0; } -- (NSURLRequest *)af_request -{ - return [self af_objectInUserInfo:AFNetworkingOperationFailingURLRequestErrorKey withError:self]; +- (NSURLRequest *)rac_request { + return [self rac_objectInUserInfo:AFNetworkingOperationFailingURLRequestErrorKey withError:self]; } -- (NSURLResponse *)af_response -{ - return [self objectInUserInfo:AFNetworkingOperationFailingURLResponseErrorKey withError:self]; +- (NSURLResponse *)rac_response { + return [self rac_objectInUserInfo:AFNetworkingOperationFailingURLResponseErrorKey withError:self]; } -- (NSData *)af_responseData -{ - return [self af_objectInUserInfo:AFNetworkingOperationFailingURLResponseDataErrorKey withError:self]; +- (NSData *)rac_responseData { + return [self rac_objectInUserInfo:AFNetworkingOperationFailingURLResponseDataErrorKey withError:self]; } -- (NSString *)af_responseString -{ - return [[NSString alloc] initWithData:[self af_objectInUserInfo:AFNetworkingOperationFailingURLResponseDataErrorKey withError:self] encoding:NSUTF8StringEncoding]; +- (NSString *)rac_responseString { + return [[NSString alloc] initWithData:[self rac_objectInUserInfo:AFNetworkingOperationFailingURLResponseDataErrorKey withError:self] encoding:NSUTF8StringEncoding]; } -- (NSString *)af_requestURL -{ - NSURLResponse* response = [self af_response]; +- (NSString *)rac_requestURL { + NSURLResponse *response = [self rac_response]; - if ([response isKindOfClass:[NSHTTPURLResponse class]]) - { - NSHTTPURLResponse* urlResponse = (NSHTTPURLResponse *)response; + if ([response isKindOfClass:[NSHTTPURLResponse class]]) { + NSHTTPURLResponse *urlResponse = (NSHTTPURLResponse *)response; return urlResponse.URL.absoluteString; } - else - { + else { return (self.originalError.userInfo[NSURLErrorFailingURLStringErrorKey]) ? self.originalError.userInfo[NSURLErrorFailingURLStringErrorKey] : nil; } } -#pragma mark - Helpers +#pragma mark - Private methods -- (id)af_objectInUserInfo:(NSString *)key withError:(NSError *)error -{ - if (error.userInfo[key]) - { - return error.userInfo[key]; - } +- (id)rac_objectInUserInfo:(NSString *)key withError:(NSError *)error { // // Check for underlying error // - NSError* underlyingError = error.userInfo[NSUnderlyingErrorKey]; + NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey]; - return (underlyingError.userInfo[key]) ? underlyingError.userInfo[key] : nil; + return error.userInfo[key] ?: underlyingError.userInfo[key]; } @end diff --git a/RACAFNetworking/RACAFNetworking.h b/RACAFNetworking/RACAFNetworking.h index f46b5bc..a91fbdf 100644 --- a/RACAFNetworking/RACAFNetworking.h +++ b/RACAFNetworking/RACAFNetworking.h @@ -9,4 +9,4 @@ #import "AFHTTPRequestOperationManager+RACSupport.h" #import "AFURLConnectionOperation+RACSupport.h" #import "AFHTTPSessionManager+RACSupport.h" -#import "NSError+AFNetworking.h" +#import "NSError+RACAFNetworking.h" From bce87f7b47d8c4b3e62f7a416132f3ca42f93217 Mon Sep 17 00:00:00 2001 From: Dal Rupnik Date: Tue, 7 Apr 2015 13:38:42 +0200 Subject: [PATCH 3/3] Removed license --- RACAFNetworking/NSError+RACAFNetworking.h | 20 -------------------- RACAFNetworking/NSError+RACAFNetworking.m | 23 ++--------------------- 2 files changed, 2 insertions(+), 41 deletions(-) diff --git a/RACAFNetworking/NSError+RACAFNetworking.h b/RACAFNetworking/NSError+RACAFNetworking.h index 7dc0cba..de73e14 100644 --- a/RACAFNetworking/NSError+RACAFNetworking.h +++ b/RACAFNetworking/NSError+RACAFNetworking.h @@ -1,28 +1,8 @@ // // NSError+AFNetworking.m // -// The MIT License (MIT) -// // Copyright (c) 2015 Dal Rupnik (https://github.com/legoless) // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// #import diff --git a/RACAFNetworking/NSError+RACAFNetworking.m b/RACAFNetworking/NSError+RACAFNetworking.m index 7e003c8..bdcbc32 100644 --- a/RACAFNetworking/NSError+RACAFNetworking.m +++ b/RACAFNetworking/NSError+RACAFNetworking.m @@ -1,31 +1,12 @@ // // NSError+RACAFNetworking.m // -// The MIT License (MIT) -// // Copyright (c) 2015 Dal Rupnik (https://github.com/legoless) // -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// #import "NSError+RACAFNetworking.h" #import "AFURLRequestSerialization.h" +#import "AFURLResponseSerialization.h" @implementation NSError (RACAFNetworking) @@ -67,7 +48,7 @@ - (NSString *)rac_requestURL { return urlResponse.URL.absoluteString; } else { - return (self.originalError.userInfo[NSURLErrorFailingURLStringErrorKey]) ? self.originalError.userInfo[NSURLErrorFailingURLStringErrorKey] : nil; + return (self.userInfo[NSURLErrorFailingURLStringErrorKey]) ? self.userInfo[NSURLErrorFailingURLStringErrorKey] : nil; } }