@@ -34,9 +34,7 @@ open class LUAutocompleteView: UIView {
3434 /// The text field to which the autocomplete view will be attached.
3535 public weak var textField : UITextField ? {
3636 didSet {
37- guard let textField = textField else {
38- return
39- }
37+ guard let textField else { return }
4038
4139 textField. addTarget ( self , action: #selector( textFieldEditingChanged) , for: . editingChanged)
4240 textField. addTarget ( self , action: #selector( textFieldEditingEnded) , for: . editingDidEnd)
@@ -52,9 +50,7 @@ open class LUAutocompleteView: UIView {
5250 */
5351 public var autocompleteCell : LUAutocompleteTableViewCell . Type ? {
5452 didSet {
55- guard let autocompleteCell = autocompleteCell else {
56- return
57- }
53+ guard let autocompleteCell else { return }
5854
5955 tableView. register ( autocompleteCell, forCellReuseIdentifier: LUAutocompleteView . cellIdentifier)
6056 tableView. reloadData ( )
@@ -84,14 +80,14 @@ open class LUAutocompleteView: UIView {
8480 return
8581 }
8682
87- guard let superview = superview else {
83+ guard let superview else {
8884 heightConstraint? . constant = ( height > maximumHeight) ? maximumHeight : height
8985 return
9086 }
9187
9288 superview. layoutIfNeeded ( )
9389 UIView . animate ( withDuration: 0.2 ) {
94- self . heightConstraint? . constant = ( self . height > self . maximumHeight) ? self . maximumHeight : self . height
90+ self . heightConstraint? . constant = min ( self . height, self . maximumHeight)
9591 superview. layoutIfNeeded ( )
9692 }
9793 }
@@ -141,7 +137,7 @@ open class LUAutocompleteView: UIView {
141137 }
142138
143139 private func setupConstraints( ) {
144- guard let textField = textField else {
140+ guard let textField else {
145141 assertionFailure ( " Sanity check " )
146142 return
147143 }
@@ -174,17 +170,15 @@ open class LUAutocompleteView: UIView {
174170 }
175171
176172 @objc private func getElements( ) {
177- guard let dataSource = dataSource else {
178- return
179- }
173+ guard let dataSource else { return }
180174
181175 guard let text = textField? . text, !text. isEmpty else {
182176 elements. removeAll ( )
183177 return
184178 }
185179
186- dataSource. autocompleteView ( self , elementsFor: text) { [ weak self] elements in
187- self ? . elements = elements
180+ dataSource. autocompleteView ( self , elementsFor: text) { [ weak self] in
181+ self ? . elements = $0
188182 }
189183 }
190184
@@ -205,7 +199,7 @@ extension LUAutocompleteView: UITableViewDataSource {
205199 - Returns: The number of rows in `section`.
206200 */
207201 public func tableView( _ tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {
208- return !( textField? . text? . isEmpty ?? true ) ? elements. count : 0
202+ !( textField? . text? . isEmpty ?? true ) ? elements. count : 0
209203 }
210204
211205 /** Asks the data source for a cell to insert in a particular location of the table view.
@@ -229,7 +223,7 @@ extension LUAutocompleteView: UITableViewDataSource {
229223
230224 let text = elements [ indexPath. row]
231225
232- guard autocompleteCell != nil , let customCell = cell as? LUAutocompleteTableViewCell else {
226+ guard autocompleteCell != nil , let customCell = cell as? LUAutocompleteTableViewCell else {
233227 cell. textLabel? . attributedText = NSAttributedString ( string: text, attributes: textAttributes)
234228 cell. selectionStyle = . none
235229
0 commit comments