[Issue #33] Changing return type of class method object contructors from id to an actual instance of that class

This commit is contained in:
Mattt Thompson 2011-09-21 15:33:20 -05:00
parent f422cafe14
commit db4c852e3d
10 changed files with 54 additions and 59 deletions

View file

@ -82,8 +82,8 @@ extern NSString * const AFHTTPOperationDidFinishNotification;
@return A new HTTP request operation @return A new HTTP request operation
*/ */
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFHTTPRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
completion:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error))completion; completion:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error))completion;
/** /**
Creates and returns an `AFHTTPRequestOperation` object and sets the specified input and output streams, and completion callback. Creates and returns an `AFHTTPRequestOperation` object and sets the specified input and output streams, and completion callback.
@ -97,10 +97,10 @@ extern NSString * const AFHTTPOperationDidFinishNotification;
@return A new HTTP request operation @return A new HTTP request operation
*/ */
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFHTTPRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
inputStream:(NSInputStream *)inputStream inputStream:(NSInputStream *)inputStream
outputStream:(NSOutputStream *)outputStream outputStream:(NSOutputStream *)outputStream
completion:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))completion; completion:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))completion;
///--------------------------------- ///---------------------------------
/// @name Setting Progress Callbacks /// @name Setting Progress Callbacks

View file

@ -134,7 +134,7 @@ static NSThread *_networkRequestThread = nil;
return _networkRequestThread; return _networkRequestThread;
} }
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFHTTPRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
completion:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error))completion completion:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error))completion
{ {
AFHTTPRequestOperation *operation = [[[self alloc] initWithRequest:urlRequest] autorelease]; AFHTTPRequestOperation *operation = [[[self alloc] initWithRequest:urlRequest] autorelease];
@ -143,10 +143,10 @@ static NSThread *_networkRequestThread = nil;
return operation; return operation;
} }
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFHTTPRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
inputStream:(NSInputStream *)inputStream inputStream:(NSInputStream *)inputStream
outputStream:(NSOutputStream *)outputStream outputStream:(NSOutputStream *)outputStream
completion:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))completion completion:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))completion
{ {
NSMutableURLRequest *mutableURLRequest = [[urlRequest mutableCopy] autorelease]; NSMutableURLRequest *mutableURLRequest = [[urlRequest mutableCopy] autorelease];
if (inputStream) { if (inputStream) {
@ -175,7 +175,7 @@ static NSThread *_networkRequestThread = nil;
self.request = urlRequest; self.request = urlRequest;
self.runLoopModes = [NSSet setWithObjects:NSRunLoopCommonModes, nil]; self.runLoopModes = [NSSet setWithObject:NSRunLoopCommonModes];
self.state = AFHTTPOperationReadyState; self.state = AFHTTPOperationReadyState;

View file

@ -25,7 +25,7 @@
@interface AFImageCache : NSCache @interface AFImageCache : NSCache
+ (id)sharedImageCache; + (AFImageCache *)sharedImageCache;
- (UIImage *)cachedImageForRequest:(NSURLRequest *)urlRequest - (UIImage *)cachedImageForRequest:(NSURLRequest *)urlRequest
cacheName:(NSString *)cacheName; cacheName:(NSString *)cacheName;

View file

@ -28,8 +28,8 @@ static inline NSString * AFImageCacheKey(NSURLRequest *urlRequest, NSString *cac
@implementation AFImageCache @implementation AFImageCache
+ (id)sharedImageCache { + (AFImageCache *)sharedImageCache {
static NSCache *_sharedImageCache = nil; static AFImageCache *_sharedImageCache = nil;
static dispatch_once_t oncePredicate; static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{ dispatch_once(&oncePredicate, ^{

View file

@ -26,13 +26,13 @@
@interface AFImageRequestOperation : AFHTTPRequestOperation @interface AFImageRequestOperation : AFHTTPRequestOperation
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFImageRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
success:(void (^)(UIImage *image))success; success:(void (^)(UIImage *image))success;
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFImageRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock
cacheName:(NSString *)cacheNameOrNil cacheName:(NSString *)cacheNameOrNil
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
@end @end

View file

@ -23,8 +23,6 @@
#import "AFImageRequestOperation.h" #import "AFImageRequestOperation.h"
#import "AFImageCache.h" #import "AFImageCache.h"
#import "UIImage+AFNetworking.h"
static dispatch_queue_t af_image_request_operation_processing_queue; static dispatch_queue_t af_image_request_operation_processing_queue;
static dispatch_queue_t image_request_operation_processing_queue() { static dispatch_queue_t image_request_operation_processing_queue() {
if (af_image_request_operation_processing_queue == NULL) { if (af_image_request_operation_processing_queue == NULL) {
@ -36,8 +34,8 @@ static dispatch_queue_t image_request_operation_processing_queue() {
@implementation AFImageRequestOperation @implementation AFImageRequestOperation
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFImageRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
success:(void (^)(UIImage *image))success success:(void (^)(UIImage *image))success
{ {
return [self operationWithRequest:urlRequest imageProcessingBlock:nil cacheName:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { return [self operationWithRequest:urlRequest imageProcessingBlock:nil cacheName:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
if (success) { if (success) {
@ -46,13 +44,13 @@ static dispatch_queue_t image_request_operation_processing_queue() {
} failure:nil]; } failure:nil];
} }
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFImageRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock
cacheName:(NSString *)cacheNameOrNil cacheName:(NSString *)cacheNameOrNil
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{ {
AFImageRequestOperation *operation = [self operationWithRequest:urlRequest completion:^(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error) { return (AFImageRequestOperation *)[self operationWithRequest:urlRequest completion:^(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error) {
dispatch_async(image_request_operation_processing_queue(), ^(void) { dispatch_async(image_request_operation_processing_queue(), ^(void) {
if (error) { if (error) {
if (failure) { if (failure) {
@ -81,8 +79,6 @@ static dispatch_queue_t image_request_operation_processing_queue() {
} }
}); });
}]; }];
return operation;
} }
@end @end

View file

@ -40,8 +40,8 @@
@return A new JSON request operation @return A new JSON request operation
*/ */
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFJSONRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
success:(void (^)(id JSON))success; success:(void (^)(id JSON))success;
/** /**
Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks. Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks.
@ -56,9 +56,9 @@
@return A new JSON request operation @return A new JSON request operation
*/ */
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFJSONRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
success:(void (^)(id JSON))success success:(void (^)(id JSON))success
failure:(void (^)(NSError *error))failure; failure:(void (^)(NSError *error))failure;
/** /**
Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks, as well as the status codes and content types that are acceptable for a successful request. Creates and returns an `AFJSONRequestOperation` object and sets the specified success and failure callbacks, as well as the status codes and content types that are acceptable for a successful request.
@ -71,11 +71,11 @@
@return A new JSON request operation @return A new JSON request operation
*/ */
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFJSONRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
acceptableStatusCodes:(NSIndexSet *)acceptableStatusCodes acceptableStatusCodes:(NSIndexSet *)acceptableStatusCodes
acceptableContentTypes:(NSSet *)acceptableContentTypes acceptableContentTypes:(NSSet *)acceptableContentTypes
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure; failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
///---------------------------------- ///----------------------------------

View file

@ -36,15 +36,15 @@ static dispatch_queue_t json_request_operation_processing_queue() {
@implementation AFJSONRequestOperation @implementation AFJSONRequestOperation
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFJSONRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
success:(void (^)(id JSON))success success:(void (^)(id JSON))success
{ {
return [self operationWithRequest:urlRequest success:success failure:nil]; return [self operationWithRequest:urlRequest success:success failure:nil];
} }
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFJSONRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
success:(void (^)(id JSON))success success:(void (^)(id JSON))success
failure:(void (^)(NSError *error))failure failure:(void (^)(NSError *error))failure
{ {
return [self operationWithRequest:urlRequest acceptableStatusCodes:[self defaultAcceptableStatusCodes] acceptableContentTypes:[self defaultAcceptableContentTypes] success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { return [self operationWithRequest:urlRequest acceptableStatusCodes:[self defaultAcceptableStatusCodes] acceptableContentTypes:[self defaultAcceptableContentTypes] success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
if (success) { if (success) {
@ -57,13 +57,13 @@ static dispatch_queue_t json_request_operation_processing_queue() {
}]; }];
} }
+ (id)operationWithRequest:(NSURLRequest *)urlRequest + (AFJSONRequestOperation *)operationWithRequest:(NSURLRequest *)urlRequest
acceptableStatusCodes:(NSIndexSet *)acceptableStatusCodes acceptableStatusCodes:(NSIndexSet *)acceptableStatusCodes
acceptableContentTypes:(NSSet *)acceptableContentTypes acceptableContentTypes:(NSSet *)acceptableContentTypes
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{ {
return [self operationWithRequest:urlRequest completion:^(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error) { return (AFJSONRequestOperation *)[self operationWithRequest:urlRequest completion:^(NSURLRequest *request, NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (!error) { if (!error) {
if (acceptableStatusCodes && ![acceptableStatusCodes containsIndex:[response statusCode]]) { if (acceptableStatusCodes && ![acceptableStatusCodes containsIndex:[response statusCode]]) {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];

View file

@ -27,5 +27,5 @@ extern NSString * const kAFGowallaClientID;
extern NSString * const kAFGowallaBaseURLString; extern NSString * const kAFGowallaBaseURLString;
@interface AFGowallaAPIClient : AFRestClient @interface AFGowallaAPIClient : AFRestClient
+ (id)sharedClient; + (AFGowallaAPIClient *)sharedClient;
@end @end

View file

@ -22,8 +22,6 @@
#import "AFGowallaAPIClient.h" #import "AFGowallaAPIClient.h"
static AFGowallaAPIClient *_sharedClient = nil;
// Replace this with your own API Key, available at http://api.gowalla.com/api/keys/ // Replace this with your own API Key, available at http://api.gowalla.com/api/keys/
NSString * const kAFGowallaClientID = @"e7ccb7d3d2414eb2af4663fc91eb2793"; NSString * const kAFGowallaClientID = @"e7ccb7d3d2414eb2af4663fc91eb2793";
@ -31,7 +29,8 @@ NSString * const kAFGowallaBaseURLString = @"https://api.gowalla.com/";
@implementation AFGowallaAPIClient @implementation AFGowallaAPIClient
+ (id)sharedClient { + (AFGowallaAPIClient *)sharedClient {
static AFGowallaAPIClient *_sharedClient = nil;
static dispatch_once_t oncePredicate; static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{ dispatch_once(&oncePredicate, ^{
_sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:kAFGowallaBaseURLString]]; _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:kAFGowallaBaseURLString]];