Objective-C Runtime: Swizzled Method Name?

In an attempt to detect backspace in UITextField , I tried to subclass UITextField and override -[UIKeyInput deleteBackward] , but it is never called. So, I suspect UITextField swizzles deleteBackward in another method name.

Using Objective-C Runtime , how can I determine which deleteBackward method deleteBackward was swizzled applied to? Then, how can I change the implementation so that the UITextField [self.delegate textField:self shouldChangeCharactersInRange:NSMakeRange(0, 0) replacementString:@""] when the delete key is pressed when it is empty.

Also, will this metaprogramming reject the app from the App Store?

+6
source share
1 answer

Swizzling does not change the name of the method. If that were the case, it would be impossible to call the method, since the runtime finds an implementation using the name. All he does is change the address of the code that runs when a particular method is called.

My guess about why the deleteBackward method deleteBackward not called is that the input system uses the method from the more complex UITextInput , most likely replaceRange:withText: Try this and make your call if the text argument is an empty string. Also make sure your swizzling function does not return an error.

+3
source

Source: https://habr.com/ru/post/899714/


All Articles