All Projects → mozilla-mobile → Autocompletetextfield

mozilla-mobile / Autocompletetextfield

Licence: mpl-2.0
An iOS text field that autocompletes text with the supplied list of words.

Programming Languages

swift
15916 projects

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!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].