From 68c572ae32b320be2b96ac010c002a3f080c9e03 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Thu, 8 Dec 2011 13:21:23 -0600 Subject: [PATCH] Refactoring -cancel and -isCancelled --- AFNetworking/AFURLConnectionOperation.m | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 4e762e5..0ef5b55 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -82,7 +82,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat @interface AFURLConnectionOperation () @property (readwrite, nonatomic, assign) AFOperationState state; -@property (readwrite, nonatomic, assign, getter = isCancelled) BOOL cancelled; @property (readwrite, nonatomic, retain) NSRecursiveLock *lock; @property (readwrite, nonatomic, assign) NSURLConnection *connection; @property (readwrite, nonatomic, retain) NSURLRequest *request; @@ -101,7 +100,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat @implementation AFURLConnectionOperation @synthesize state = _state; -@synthesize cancelled = _cancelled; @synthesize connection = _connection; @synthesize runLoopModes = _runLoopModes; @synthesize request = _request; @@ -247,14 +245,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat [self.lock unlock]; } -- (void)setCancelled:(BOOL)cancelled { - [self.lock lock]; - [self willChangeValueForKey:@"isCancelled"]; - _cancelled = cancelled; - [self didChangeValueForKey:@"isCancelled"]; - [self.lock unlock]; -} - - (NSString *)responseString { [self.lock lock]; if (!_responseString && self.response && self.responseData) { @@ -284,6 +274,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat return self.state == AFHTTPOperationFinishedState; } +- (BOOL)isCancelled { + return _cancelled; +} + - (BOOL)isConcurrent { return YES; } @@ -325,8 +319,8 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat if (![self isFinished] && ![self isCancelled]) { [super cancel]; - self.cancelled = YES; - + [self willChangeValueForKey:@"isCancelled"]; + _cancelled = YES; if (self.connection) { [self.connection cancel]; @@ -334,6 +328,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat NSDictionary *userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo]]; } + [self didChangeValueForKey:@"isCancelled"]; } [self.lock unlock]; }