override的简单示例
overrideAppDelegate.h
#import "NSString+Addition.h"#import <objc/objc-class.h>#define CSTRING_CUSTOM_ADDITON "^_^"@implementation NSString (NSString_Addition)- (const char *)ovUTF8String {char *sOriginal = (char *)[self ovUTF8String];int iOrgLen = (NULL == sOriginal ? 0 : strlen(sOriginal));char *sCustom = (char *)malloc(iOrgLen + strlen(CSTRING_CUSTOM_ADDITON) + 1); if (NULL != sCustom) { if (NULL != sOriginal) { strcpy(sCustom, sOriginal); } strcat(sCustom, CSTRING_CUSTOM_ADDITON); }return (const char *)sCustom;}+ (BOOL)swizze { Method oldMethod = class_getInstanceMethod(self, NSSelectorFromString(@"UTF8String")); if (!oldMethod)return NO;Method newMethod = class_getInstanceMethod(self, NSSelectorFromString(@"ovUTF8String"));if (!newMethod)return NO;method_exchangeImplementations(oldMethod, newMethod);return YES;}@end