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
You can just attach an IBAction to your Sent Events (editing changed) of your textfield to filter non numbers out of your string as you type as follow:
@IBAction func changedTextAction(_ sender: UITextField) {
sender.text = sender.text?.filter(\.isWholeNumber)
}
This will allow the user to paste into the field but it will filter all non digits from the string.