Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when insert same character with the patternSymbol, will happen crash! #39

Closed
ericchuhong opened this issue Jun 17, 2021 · 4 comments
Closed

Comments

@ericchuhong
Copy link

eg: current textfield exist "8123456#",then, if your insert other number,will crash。Console show

Fatal error: String index is out of bounds: file Swift/StringCharacterView.swift, line 60

@ericchuhong ericchuhong changed the title when insert same character with the patternSymbol, will cause crash! when insert same character with the patternSymbol, will happen crash! Jun 17, 2021
@luximetr
Copy link
Owner

eg: current textfield exist "8123456#",then, if your insert other number,will crash。Console show

Fatal error: String index is out of bounds: file Swift/StringCharacterView.swift, line 60

Will investigate it, can you please share how do you create a formatter, that crashes.

@ericchuhong
Copy link
Author

ericchuhong commented Jun 21, 2021

Here is my code to create formatter.

···
/// SubClass inheritance from TextFieldInputController
class MeetingNumberInputDelegator: TextFieldInputController {
    override func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        /// filter space in string
        let inputStr = string.replacingOccurrences(of: " ", with: "", options: .literal, range: nil)
        return super.textField(textField, shouldChangeCharactersIn: range, replacementString: inputStr)
    }
}
···
/// Define in view
var meetingNumberInputController = MeetingNumberInputDelegator()
var meetingNumberFormatter : DefaultTextInputFormatter = {
      let formatter = DefaultTextInputFormatter(textPattern: "### #### ########")
      return formatter
}()
···
/// Use
inputNoField.delegate = meetingNumberInputController
meetingNumberInputController.formatter = meetingNumberFormatter

@luximetr
Copy link
Owner

eg: current textfield exist "8123456#",then, if your insert other number,will crash。Console show

Fatal error: String index is out of bounds: file Swift/StringCharacterView.swift, line 60

I can suggest you a quick fix, during init of formatter you can pass pattern symbol parameter and set it to some other symbol. Later I will try to fix this crash.

@luximetr
Copy link
Owner

luximetr commented Jan 27, 2022

Fixed at 2.5.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants