I\'ve got a TextField with a numberPad and the function runs only if it contains numbers.
The user will crash the app if they paste letters
For Swift 5
UIResponderStandardEditActions has been added recently (iOS 10.0+) through which we can safely check if action is "paste" or not.
import UIKit
class NMTextField: UITextField {
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.paste(_:)) {
return false
}
return super.canPerformAction(action, withSender: sender)
}
}