This commit is contained in:
Mattt Thompson 2012-06-26 09:34:08 -07:00
parent 605bbf1c28
commit ea94ea6ffa

View file

@ -54,11 +54,10 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) {
return [NSSet setWithSet:mutableContentTypes]; return [NSSet setWithSet:mutableContentTypes];
} }
static void AFSwizzleClassMethodWithImplementation(Class klass, SEL selector, IMP implementation) { static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, void *block) {
Method originalMethod = class_getClassMethod(klass, selector); Method originalMethod = class_getClassMethod(klass, selector);
if (method_getImplementation(originalMethod) != implementation) { IMP implementation = imp_implementationWithBlock(block);
class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod));
}
} }
static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
@ -259,10 +258,6 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) {
#pragma mark - AFHTTPRequestOperation #pragma mark - AFHTTPRequestOperation
static id AFStaticClassValueImplementation(id self, SEL _cmd) {
return objc_getAssociatedObject([self class], _cmd);
}
+ (NSIndexSet *)acceptableStatusCodes { + (NSIndexSet *)acceptableStatusCodes {
return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)]; return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)];
} }
@ -270,9 +265,9 @@ static id AFStaticClassValueImplementation(id self, SEL _cmd) {
+ (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes { + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes {
NSMutableIndexSet *mutableStatusCodes = [[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]]; NSMutableIndexSet *mutableStatusCodes = [[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]];
[mutableStatusCodes addIndexes:statusCodes]; [mutableStatusCodes addIndexes:statusCodes];
SEL selector = @selector(acceptableStatusCodes); AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), (__bridge void *)^(id _self) {
AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation); return mutableStatusCodes;
objc_setAssociatedObject([self class], selector, mutableStatusCodes, OBJC_ASSOCIATION_COPY_NONATOMIC); });
} }
+ (NSSet *)acceptableContentTypes { + (NSSet *)acceptableContentTypes {
@ -282,9 +277,9 @@ static id AFStaticClassValueImplementation(id self, SEL _cmd) {
+ (void)addAcceptableContentTypes:(NSSet *)contentTypes { + (void)addAcceptableContentTypes:(NSSet *)contentTypes {
NSMutableSet *mutableContentTypes = [[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES]; NSMutableSet *mutableContentTypes = [[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES];
[mutableContentTypes unionSet:contentTypes]; [mutableContentTypes unionSet:contentTypes];
SEL selector = @selector(acceptableContentTypes); AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), (__bridge void *)^(id _self) {
AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation); return mutableContentTypes;
objc_setAssociatedObject([self class], selector, mutableContentTypes, OBJC_ASSOCIATION_COPY_NONATOMIC); });
} }
+ (BOOL)canProcessRequest:(NSURLRequest *)request { + (BOOL)canProcessRequest:(NSURLRequest *)request {