Skip to content

Commit

Permalink
feat: guard the weak self
Browse files Browse the repository at this point in the history
  • Loading branch information
MojtabaHs committed May 20, 2024
1 parent 611793c commit f6579ae
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Sources/iPhoneNumberField/iPhoneNumberField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,18 @@ public struct iPhoneNumberField: UIViewRepresentable {
}

public func textFieldDidBeginEditing(_ textField: UITextField) {
DispatchQueue.main.async { [isFirstResponder] in
DispatchQueue.main.async { [weak self] in
guard let self else { return }
isFirstResponder.wrappedValue = true
self.onBeginEditing(textField as! PhoneNumberTextField)
onBeginEditing(textField as! PhoneNumberTextField)
}
}

public func textFieldDidEndEditing(_ textField: UITextField) {
DispatchQueue.main.async { [isFirstResponder] in
DispatchQueue.main.async { [weak self] in
guard let self else { return }
isFirstResponder.wrappedValue = false
self.onBeginEditing(textField as! PhoneNumberTextField)
onBeginEditing(textField as! PhoneNumberTextField)
}
}

Expand Down

0 comments on commit f6579ae

Please sign in to comment.