Skip to content

Commit

Permalink
Fix retain cycle between FormattedTextField and `TextFieldDelegateP…
Browse files Browse the repository at this point in the history
…roxy`
  • Loading branch information
seaburg committed Oct 23, 2016
1 parent d71bd60 commit 9b1aab2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion FormattedTextField/FormattedTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@ open class FormattedTextField: UITextField {
}
private let placeholderLabel: UILabel

private lazy var delegateProxy: TextFieldDelegateProxy = TextFieldDelegateProxy(shouldChangeFunc: self.shouldChangeCharacters(in:replacementString:))
private lazy var delegateProxy: TextFieldDelegateProxy = {
let shouldChangeFunc: (NSRange, String) -> Bool = { [unowned self] (range, string) in
return self.shouldChangeCharacters(in: range, replacementString: string)
}
return TextFieldDelegateProxy(shouldChangeFunc: shouldChangeFunc)
}()

private func shouldChangeCharacters(in range: NSRange, replacementString string: String) -> Bool {
let formattedText = self.formattedText ?? ""
Expand Down

0 comments on commit 9b1aab2

Please sign in to comment.