From 0470f4b29fc664009a57d960df01ea0a25925e5b Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 4 Apr 2012 16:31:52 -0700 Subject: [PATCH 1/8] [Issue #278] Adding thread safety to incrementing / decrementing and display of network activity indicator --- .../AFNetworkActivityIndicatorManager.m | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index a376d81..bdcb69a 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -30,6 +30,7 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; @interface AFNetworkActivityIndicatorManager () @property (readwrite, nonatomic, assign) NSInteger activityCount; @property (readwrite, nonatomic, retain) NSTimer *activityIndicatorVisibilityTimer; +@property (readwrite, nonatomic, retain) NSRecursiveLock *lock; @property (readonly, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible; - (void)updateNetworkActivityIndicatorVisibility; @@ -38,6 +39,7 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; @implementation AFNetworkActivityIndicatorManager @synthesize activityCount = _activityCount; @synthesize activityIndicatorVisibilityTimer = _activityIndicatorVisibilityTimer; +@synthesize lock = _lock; @synthesize enabled = _enabled; @dynamic networkActivityIndicatorVisible; @@ -56,6 +58,8 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; if (!self) { return nil; } + + self.lock = [[[NSRecursiveLock alloc] init] autorelease]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incrementActivityCount) name:AFNetworkingOperationDidStartNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(decrementActivityCount) name:AFNetworkingOperationDidFinishNotification object:nil]; @@ -69,10 +73,13 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; [_activityIndicatorVisibilityTimer invalidate]; [_activityIndicatorVisibilityTimer release]; _activityIndicatorVisibilityTimer = nil; + [_lock release]; + [super dealloc]; } - (void)setActivityCount:(NSInteger)activityCount { + [self.lock lock]; [self willChangeValueForKey:@"activityCount"]; _activityCount = MAX(activityCount, 0); [self didChangeValueForKey:@"activityCount"]; @@ -87,6 +94,7 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; [self updateNetworkActivityIndicatorVisibility]; } } + [self.lock unlock]; } - (BOOL)isNetworkActivityIndicatorVisible { @@ -94,19 +102,21 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; } - (void)updateNetworkActivityIndicatorVisibility { - [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]]; + dispatch_async(dispatch_get_main_queue(), ^{ + [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]]; + }); } - (void)incrementActivityCount { - @synchronized(self) { - self.activityCount += 1; - } + [self.lock lock]; + self.activityCount += 1; + [self.lock unlock]; } - (void)decrementActivityCount { - @synchronized(self) { - self.activityCount -= 1; - } + [self.lock lock]; + self.activityCount -= 1; + [self.lock unlock]; } @end From 88920034e2770ab86fa39f5cce1f334c2455a342 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 4 Apr 2012 17:17:06 -0700 Subject: [PATCH 2/8] fixes a blocked reload button once we hit an error. Also shows an alert now. --- .../Classes/Controllers/PublicTimelineViewController.m | 6 ++++-- iOS Example/Classes/Models/Tweet.m | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/iOS Example/Classes/Controllers/PublicTimelineViewController.m b/iOS Example/Classes/Controllers/PublicTimelineViewController.m index 8da1159..966b607 100644 --- a/iOS Example/Classes/Controllers/PublicTimelineViewController.m +++ b/iOS Example/Classes/Controllers/PublicTimelineViewController.m @@ -42,8 +42,10 @@ self.navigationItem.rightBarButtonItem.enabled = NO; [Tweet publicTimelineTweetsWithBlock:^(NSArray *tweets) { - _tweets = tweets; - [self.tableView reloadData]; + if (tweets) { + _tweets = tweets; + [self.tableView reloadData]; + } [_activityIndicatorView stopAnimating]; self.navigationItem.rightBarButtonItem.enabled = YES; diff --git a/iOS Example/Classes/Models/Tweet.m b/iOS Example/Classes/Models/Tweet.m index f53359d..d6bc1ec 100644 --- a/iOS Example/Classes/Models/Tweet.m +++ b/iOS Example/Classes/Models/Tweet.m @@ -65,6 +65,12 @@ } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); + + [[[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Ok", nil] show]; + + if (block) { + block(nil); + } }]; } From 069615a20d4c0de41cc3927d8cae5a16f0710c64 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 5 Apr 2012 17:29:18 -0700 Subject: [PATCH 3/8] Use lightweight locking for activityCount Also exposes isNetworkActivityIndicatorVisible which now is KVO observable. --- .../AFNetworkActivityIndicatorManager.h | 12 +++--- .../AFNetworkActivityIndicatorManager.m | 41 ++++++++++--------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.h b/AFNetworking/AFNetworkActivityIndicatorManager.h index d15384a..2cee153 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.h +++ b/AFNetworking/AFNetworkActivityIndicatorManager.h @@ -30,12 +30,7 @@ /** `AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a network request operation has started or finished, and start or stop animating the indicator accordingly. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero. */ -@interface AFNetworkActivityIndicatorManager : NSObject { -@private - NSInteger _activityCount; - BOOL _enabled; - NSTimer *_activityIndicatorVisibilityTimer; -} +@interface AFNetworkActivityIndicatorManager : NSObject; /** A Boolean value indicating whether the manager is enabled. @@ -61,6 +56,11 @@ */ - (void)decrementActivityCount; +/** + Returns the network indicator visibility. This is more excact than polling [UIApplication sharedApplication] isNetworkActivityIndicatorVisible] since we add a slight delay while updating the indicator to avoid flickering. You can observe this via KVO. + */ +- (BOOL)isNetworkActivityIndicatorVisible; + @end #endif diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index bdcb69a..32dbbe0 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -23,6 +23,7 @@ #import "AFNetworkActivityIndicatorManager.h" #import "AFHTTPRequestOperation.h" +#import #if __IPHONE_OS_VERSION_MIN_REQUIRED static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; @@ -30,7 +31,6 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; @interface AFNetworkActivityIndicatorManager () @property (readwrite, nonatomic, assign) NSInteger activityCount; @property (readwrite, nonatomic, retain) NSTimer *activityIndicatorVisibilityTimer; -@property (readwrite, nonatomic, retain) NSRecursiveLock *lock; @property (readonly, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible; - (void)updateNetworkActivityIndicatorVisibility; @@ -39,7 +39,6 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; @implementation AFNetworkActivityIndicatorManager @synthesize activityCount = _activityCount; @synthesize activityIndicatorVisibilityTimer = _activityIndicatorVisibilityTimer; -@synthesize lock = _lock; @synthesize enabled = _enabled; @dynamic networkActivityIndicatorVisible; @@ -59,8 +58,6 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; return nil; } - self.lock = [[[NSRecursiveLock alloc] init] autorelease]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(incrementActivityCount) name:AFNetworkingOperationDidStartNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(decrementActivityCount) name:AFNetworkingOperationDidFinishNotification object:nil]; @@ -73,17 +70,10 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; [_activityIndicatorVisibilityTimer invalidate]; [_activityIndicatorVisibilityTimer release]; _activityIndicatorVisibilityTimer = nil; - [_lock release]; - [super dealloc]; } -- (void)setActivityCount:(NSInteger)activityCount { - [self.lock lock]; - [self willChangeValueForKey:@"activityCount"]; - _activityCount = MAX(activityCount, 0); - [self didChangeValueForKey:@"activityCount"]; - +- (void)updateNetworkActivityIndicatorVisibilityDelayed { if (self.enabled) { // Delay hiding of activity indicator for a short interval, to avoid flickering if (![self isNetworkActivityIndicatorVisible]) { @@ -94,11 +84,10 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; [self updateNetworkActivityIndicatorVisibility]; } } - [self.lock unlock]; } - (BOOL)isNetworkActivityIndicatorVisible { - return self.activityCount > 0; + return _activityCount > 0; } - (void)updateNetworkActivityIndicatorVisibility { @@ -107,16 +96,28 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; }); } +// not actually exposed, but will be used if someone tries to set activityCount via KVC. +- (void)setActivityCount:(NSInteger)activityCount { + __sync_swap(&_activityCount, activityCount); + [self updateNetworkActivityIndicatorVisibilityDelayed]; +} + - (void)incrementActivityCount { - [self.lock lock]; - self.activityCount += 1; - [self.lock unlock]; + [self willChangeValueForKey:@"activityCount"]; + OSAtomicIncrement32((int32_t*)&_activityCount); + [self didChangeValueForKey:@"activityCount"]; + [self updateNetworkActivityIndicatorVisibilityDelayed]; } - (void)decrementActivityCount { - [self.lock lock]; - self.activityCount -= 1; - [self.lock unlock]; + [self willChangeValueForKey:@"activityCount"]; + OSAtomicDecrement32((int32_t*)&_activityCount); + [self didChangeValueForKey:@"activityCount"]; + [self updateNetworkActivityIndicatorVisibilityDelayed]; +} + ++ (NSSet *)keyPathsForValuesAffectingIsNetworkActivityIndicatorVisible { + return [NSSet setWithObject:@"activityCount"]; } @end From e2751e6ffc0c88e2c3b58418d708daee60b3c135 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 5 Apr 2012 17:49:08 -0700 Subject: [PATCH 4/8] protect decrementActivityCount against integer underflow. --- AFNetworking/AFNetworkActivityIndicatorManager.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index 32dbbe0..3e36ba6 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -111,7 +111,11 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; - (void)decrementActivityCount { [self willChangeValueForKey:@"activityCount"]; - OSAtomicDecrement32((int32_t*)&_activityCount); + bool success; + do { + int32_t orig = _activityCount; + success = OSAtomicCompareAndSwap32(orig, MIN(orig - 1, orig), &_activityCount); + } while(!success); [self didChangeValueForKey:@"activityCount"]; [self updateNetworkActivityIndicatorVisibilityDelayed]; } From ed4c5587555ae730c17adeec11830f31f64e7fbd Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 6 Apr 2012 01:46:58 -0700 Subject: [PATCH 5/8] remote obsolete KVO change calls. See http://petersteinberger.com/blog/2012/dont-call-willchangevalueforkey/. I didn't remove the call in the AFNetworkActivityIndicatorManager, since I already removed this in my other pull request. --- AFNetworking/AFImageRequestOperation.m | 2 -- iOS Example/Classes/Views/TweetTableViewCell.m | 2 -- 2 files changed, 4 deletions(-) diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index 971cd14..d2943d2 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -170,9 +170,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { return; } - [self willChangeValueForKey:@"imageScale"]; _imageScale = imageScale; - [self didChangeValueForKey:@"imageScale"]; self.responseImage = nil; } diff --git a/iOS Example/Classes/Views/TweetTableViewCell.m b/iOS Example/Classes/Views/TweetTableViewCell.m index 6fee1c0..f44c1f9 100644 --- a/iOS Example/Classes/Views/TweetTableViewCell.m +++ b/iOS Example/Classes/Views/TweetTableViewCell.m @@ -50,9 +50,7 @@ } - (void)setTweet:(Tweet *)tweet { - [self willChangeValueForKey:@"tweet"]; _tweet = tweet; - [self didChangeValueForKey:@"tweet"]; self.textLabel.text = _tweet.user.username; self.detailTextLabel.text = _tweet.text; From 6923e31db5b94052c4fcdd031ada4036ba758dcf Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Sun, 8 Apr 2012 12:02:19 -0700 Subject: [PATCH 6/8] Minor code re-formatting and documentation changes --- AFNetworking/AFNetworkActivityIndicatorManager.h | 12 ++++++------ AFNetworking/AFNetworkActivityIndicatorManager.m | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.h b/AFNetworking/AFNetworkActivityIndicatorManager.h index 2cee153..4a5640c 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.h +++ b/AFNetworking/AFNetworkActivityIndicatorManager.h @@ -30,7 +30,7 @@ /** `AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a network request operation has started or finished, and start or stop animating the indicator accordingly. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero. */ -@interface AFNetworkActivityIndicatorManager : NSObject; +@interface AFNetworkActivityIndicatorManager : NSObject /** A Boolean value indicating whether the manager is enabled. @@ -39,6 +39,11 @@ */ @property (nonatomic, assign, getter = isEnabled) BOOL enabled; +/** + A Boolean value indicating whether the network activity indicator is currently displayed in the status bar. + */ +@property (readonly, nonatomic, assign) BOOL isNetworkActivityIndicatorVisible; + /** Returns the shared network activity indicator manager object for the system. @@ -56,11 +61,6 @@ */ - (void)decrementActivityCount; -/** - Returns the network indicator visibility. This is more excact than polling [UIApplication sharedApplication] isNetworkActivityIndicatorVisible] since we add a slight delay while updating the indicator to avoid flickering. You can observe this via KVO. - */ -- (BOOL)isNetworkActivityIndicatorVisible; - @end #endif diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index 3e36ba6..01a6851 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -96,7 +96,7 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; }); } -// not actually exposed, but will be used if someone tries to set activityCount via KVC. +// Not exposed, but used if activityCount is set via KVC. - (void)setActivityCount:(NSInteger)activityCount { __sync_swap(&_activityCount, activityCount); [self updateNetworkActivityIndicatorVisibilityDelayed]; @@ -113,8 +113,8 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; [self willChangeValueForKey:@"activityCount"]; bool success; do { - int32_t orig = _activityCount; - success = OSAtomicCompareAndSwap32(orig, MIN(orig - 1, orig), &_activityCount); + int32_t currentCount = _activityCount; + success = OSAtomicCompareAndSwap32(currentCount, MIN(currentCount - 1, currentCount), &_activityCount); } while(!success); [self didChangeValueForKey:@"activityCount"]; [self updateNetworkActivityIndicatorVisibilityDelayed]; From 14aea9ee58b70278ca2fc6ece17d0c4f4aa33929 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Sun, 8 Apr 2012 14:26:52 -0700 Subject: [PATCH 7/8] [Issue #268] Reverting to cacheing UIImages rather than NSPurgeableData-wrapped image data --- AFNetworking/UIImageView+AFNetworking.m | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/AFNetworking/UIImageView+AFNetworking.m b/AFNetworking/UIImageView+AFNetworking.m index 9f9d190..5310e71 100644 --- a/AFNetworking/UIImageView+AFNetworking.m +++ b/AFNetworking/UIImageView+AFNetworking.m @@ -28,8 +28,8 @@ @interface AFImageCache : NSCache - (UIImage *)cachedImageForRequest:(NSURLRequest *)request; -- (void)cacheImageData:(NSData *)imageData - forRequest:(NSURLRequest *)request; +- (void)cacheImage:(UIImage *)image + forRequest:(NSURLRequest *)request; @end #pragma mark - @@ -121,7 +121,7 @@ static char kAFImageRequestOperationObjectKey; success(operation.request, operation.response, responseObject); } - [[[self class] af_sharedImageCache] cacheImageData:operation.responseData forRequest:urlRequest]; + [[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest]; self.af_imageRequestOperation = nil; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { @@ -162,18 +162,13 @@ static inline NSString * AFImageCacheKeyFromURLRequest(NSURLRequest *request) { break; } - UIImage *image = [UIImage imageWithData:[self objectForKey:AFImageCacheKeyFromURLRequest(request)]]; - if (image) { - return [UIImage imageWithCGImage:[image CGImage] scale:[[UIScreen mainScreen] scale] orientation:image.imageOrientation]; - } - - return image; + return [self objectForKey:AFImageCacheKeyFromURLRequest(request)]; } -- (void)cacheImageData:(NSData *)imageData - forRequest:(NSURLRequest *)request +- (void)cacheImage:(UIImage *)image + forRequest:(NSURLRequest *)request { - [self setObject:[NSPurgeableData dataWithData:imageData] forKey:AFImageCacheKeyFromURLRequest(request)]; + [self setObject:image forKey:AFImageCacheKeyFromURLRequest(request)]; } @end From 407374746c7106118f5a38136f5d700f216a32af Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Sun, 8 Apr 2012 15:25:20 -0700 Subject: [PATCH 8/8] Removing unnecessary ivar declaration in headers --- AFNetworking/AFHTTPClient.h | 10 +--------- AFNetworking/AFHTTPRequestOperation.h | 9 +-------- AFNetworking/AFImageRequestOperation.h | 10 +--------- AFNetworking/AFJSONRequestOperation.h | 6 +----- AFNetworking/AFPropertyListRequestOperation.h | 8 +------- AFNetworking/AFURLConnectionOperation.h | 19 +------------------ AFNetworking/AFURLConnectionOperation.m | 6 ++---- AFNetworking/AFXMLRequestOperation.h | 9 +-------- 8 files changed, 9 insertions(+), 68 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 687b9fd..e3d13b1 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -113,15 +113,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete [NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/ */ -@interface AFHTTPClient : NSObject { -@private - NSURL *_baseURL; - NSStringEncoding _stringEncoding; - AFHTTPClientParameterEncoding _parameterEncoding; - NSMutableArray *_registeredHTTPOperationClassNames; - NSMutableDictionary *_defaultHeaders; - NSOperationQueue *_operationQueue; -} +@interface AFHTTPClient : NSObject ///--------------------------------------- /// @name Accessing HTTP Client Properties diff --git a/AFNetworking/AFHTTPRequestOperation.h b/AFNetworking/AFHTTPRequestOperation.h index 122099e..d906129 100644 --- a/AFNetworking/AFHTTPRequestOperation.h +++ b/AFNetworking/AFHTTPRequestOperation.h @@ -26,14 +26,7 @@ /** `AFHTTPRequestOperation` is a subclass of `AFURLConnectionOperation` for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request. */ -@interface AFHTTPRequestOperation : AFURLConnectionOperation { -@private - NSIndexSet *_acceptableStatusCodes; - NSSet *_acceptableContentTypes; - NSError *_HTTPError; - dispatch_queue_t _successCallbackQueue; - dispatch_queue_t _failureCallbackQueue; -} +@interface AFHTTPRequestOperation : AFURLConnectionOperation ///---------------------------------------------- /// @name Getting HTTP URL Connection Information diff --git a/AFNetworking/AFImageRequestOperation.h b/AFNetworking/AFImageRequestOperation.h index 7456d5f..7a7f78a 100644 --- a/AFNetworking/AFImageRequestOperation.h +++ b/AFNetworking/AFImageRequestOperation.h @@ -49,15 +49,7 @@ - `image/x-xbitmap` - `image/x-win-bitmap` */ -@interface AFImageRequestOperation : AFHTTPRequestOperation { -@private -#if __IPHONE_OS_VERSION_MIN_REQUIRED - UIImage *_responseImage; - CGFloat _imageScale; -#elif __MAC_OS_X_VERSION_MIN_REQUIRED - NSImage *_responseImage; -#endif -} +@interface AFImageRequestOperation : AFHTTPRequestOperation /** An image constructed from the response data. If an error occurs during the request, `nil` will be returned, and the `error` property will be set to the error. diff --git a/AFNetworking/AFJSONRequestOperation.h b/AFNetworking/AFJSONRequestOperation.h index 7c6a579..a1191f9 100644 --- a/AFNetworking/AFJSONRequestOperation.h +++ b/AFNetworking/AFJSONRequestOperation.h @@ -35,11 +35,7 @@ @warning JSON parsing will automatically use JSONKit, SBJSON, YAJL, or NextiveJSON, if provided. Otherwise, the built-in `NSJSONSerialization` class is used, if available (iOS 5.0 and Mac OS 10.7). If the build target does not either support `NSJSONSerialization` or include a third-party JSON library, a runtime exception will be thrown when attempting to parse a JSON request. */ -@interface AFJSONRequestOperation : AFHTTPRequestOperation { -@private - id _responseJSON; - NSError *_JSONError; -} +@interface AFJSONRequestOperation : AFHTTPRequestOperation ///---------------------------- /// @name Getting Response Data diff --git a/AFNetworking/AFPropertyListRequestOperation.h b/AFNetworking/AFPropertyListRequestOperation.h index 150041c..aa6e471 100644 --- a/AFNetworking/AFPropertyListRequestOperation.h +++ b/AFNetworking/AFPropertyListRequestOperation.h @@ -32,13 +32,7 @@ - `application/x-plist` */ -@interface AFPropertyListRequestOperation : AFHTTPRequestOperation { -@private - id _responsePropertyList; - NSPropertyListFormat _propertyListFormat; - NSPropertyListReadOptions _propertyListReadOptions; - NSError *_propertyListError; -} +@interface AFPropertyListRequestOperation : AFHTTPRequestOperation ///---------------------------- /// @name Getting Response Data diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 14d0226..bef89dc 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -75,24 +75,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; @warning Attempting to load a `file://` URL in iOS 4 may result in an `NSInvalidArgumentException`, caused by the connection returning `NSURLResponse` rather than `NSHTTPURLResponse`, which is the behavior as of iOS 5. */ -@interface AFURLConnectionOperation : NSOperation { -@private - unsigned short _state; - BOOL _cancelled; - NSRecursiveLock *_lock; - - NSSet *_runLoopModes; - - NSURLConnection *_connection; - NSURLRequest *_request; - NSHTTPURLResponse *_response; - NSError *_error; - - NSData *_responseData; - NSInteger _totalBytesRead; - NSMutableData *_dataAccumulator; - NSOutputStream *_outputStream; -} +@interface AFURLConnectionOperation : NSOperation ///------------------------------- /// @name Accessing Run Loop Modes diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 172595a..fe520e2 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -85,6 +85,7 @@ 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, retain) NSURLConnection *connection; @property (readwrite, nonatomic, retain) NSURLRequest *request; @@ -106,6 +107,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat @implementation AFURLConnectionOperation @synthesize state = _state; +@synthesize cancelled = _cancelled; @synthesize connection = _connection; @synthesize runLoopModes = _runLoopModes; @synthesize request = _request; @@ -304,10 +306,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat return self.state == AFHTTPOperationFinishedState; } -- (BOOL)isCancelled { - return _cancelled; -} - - (BOOL)isConcurrent { return YES; } diff --git a/AFNetworking/AFXMLRequestOperation.h b/AFNetworking/AFXMLRequestOperation.h index 7fa919d..0beb677 100644 --- a/AFNetworking/AFXMLRequestOperation.h +++ b/AFNetworking/AFXMLRequestOperation.h @@ -39,14 +39,7 @@ When `AFXMLRequestOperation` is registered with `AFHTTPClient`, the response object in the success callback of `HTTPRequestOperationWithRequest:success:failure:` will be an instance of `NSXMLParser`. On platforms that support `NSXMLDocument`, you have the option to ignore the response object, and simply use the `responseXMLDocument` property of the operation argument of the callback. */ -@interface AFXMLRequestOperation : AFHTTPRequestOperation { -@private - NSXMLParser *_responseXMLParser; -#if __MAC_OS_X_VERSION_MIN_REQUIRED - NSXMLDocument *_responseXMLDocument; -#endif - NSError *_XMLError; -} +@interface AFXMLRequestOperation : AFHTTPRequestOperation ///---------------------------- /// @name Getting Response Data