I have adopted Mattt Thompson Method Swizzling code in my project(Thanks to Mattt Thompson!), it works very well in iOS 7 and earlier, but in iOS 8, it seems like that method swizzling doesn't work any more, deleteBackwardSwizzle is never called, the code is as follows:
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
// When swizzling a class method, use the following:
// Class class = object_getClass((id)self);
SEL originalSelector = @selector(deleteBackward);
SEL swizzledSelector = @selector(deleteBackwardSwizzle);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});