Skip to content

amlynarczyk/AutocompleteTextField

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutocompleteTextField

An iOS text field that autocompletes text with the supplied list of words.

Usage

import AutocompleteTextField

// First implement the completion source:
extension ViewController: AutocompleteTextFieldCompletionSource {
    func autocompleteTextFieldCompletionSource(_ autocompleteTextField: AutocompleteTextField, forText text: String) -> String? {
        guard !text.isEmpty else { return nil }
        return domains.first { $0.hasPrefix(text) }
    }
}

class ViewController: UIViewController {
    let domains = ["mozilla.org", "google.com", "wikipedia.org"]

    override func viewDidLoad() {
        // Then create an AutocompleteTextField, attaching our source:
        let textField = AutocompleteTextField()
        textField.completionSource = self
        view.addSubview(textField)
        ...
    }
}

To see this in action, run the example project!

About

An iOS text field that autocompletes text with the supplied list of words.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 96.1%
  • Objective-C 3.9%