Last active
December 20, 2015 03:59
-
-
Save stevegraham/6067333 to your computer and use it in GitHub Desktop.
parseport - leave parse whenever you want
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString * const kAPIEndpoint = @"http://127.0.0.1:3000/"; | |
void SwizzleInstanceMethod(Class class, SEL dstSel, SEL srcSel) { | |
Method dstMethod = class_getInstanceMethod(class, dstSel); | |
Method srcMethod = class_getInstanceMethod(class, srcSel); | |
if (class_addMethod(class, dstSel, method_getImplementation(srcMethod), method_getTypeEncoding(srcMethod))) { | |
class_replaceMethod(class, dstSel, method_getImplementation(dstMethod), method_getTypeEncoding(dstMethod)); | |
} else { | |
method_exchangeImplementations(dstMethod, srcMethod); | |
} | |
} | |
void SwizzleClassMethod(Class class, SEL dstSel, SEL srcSel) { | |
Class metaClass = object_getClass(class); | |
SwizzleInstanceMethod(metaClass, dstSel, srcSel); | |
} | |
@interface PF_AFHTTPClient | |
+(instancetype)clientWithBaseURL:(NSURL *)baseURL; | |
-(instancetype)initWithBaseURL:(NSURL *)baseURL; | |
@end | |
@implementation PF_AFHTTPClient (parseport) | |
+(instancetype)parseportClientWithBaseURL:(NSURL *)baseURL { | |
NSURL * url = [NSURL URLWithString:kAPIEndpoint]; | |
return [self parseportClientWithBaseURL:url]; | |
} | |
-(instancetype)parseportInitWithBaseURL:(NSURL *)baseURL { | |
NSURL * url = [NSURL URLWithString:kAPIEndpoint]; | |
return [self parseportInitWithBaseURL:url]; | |
} | |
+ (void)load { | |
SwizzleClassMethod(self, @selector(clientWithBaseURL:), @selector(parseportClientWithBaseURL:)); | |
SwizzleInstanceMethod(self, @selector(initWithBaseURL:), @selector(parseportInitWithBaseURL:)); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment