0

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);
    }
});
lmnbeyond
  • 6,383
  • 2
  • 18
  • 18

1 Answers1

0

After some further study in this deleteBackward method, I figured out that it has nothing to do with swizzling. I followed the instructions from detect-backspace-in-uitextfield-in-ios8 and everything works well again!

Community
  • 1
  • 1
lmnbeyond
  • 6,383
  • 2
  • 18
  • 18