Skip to content

A SwiftUI package that provides a TextField with a Picker as its input view. The picker replaces the keyboard as the input view for the TextField.

License

Notifications You must be signed in to change notification settings

dan-codes1/TextFieldPicker

Repository files navigation

TextFieldPicker

A SwiftUI package that provides a TextField with a Picker as its input view. The picker replaces the keyboard as the input view for the TextField.

Example.mp4

Requirements

  • iOS 13.0+
  • macOS 10.13+
  • Swift 5.0+

Installation

Swift Package Manager

To add TextFieldPicker to your Xcode project:

  1. In Xcode, open your project and select File > Add Packages.
  2. Paste the repository URL: https://github.com/dan-codes1/TextFieldPicker.
  3. Choose the package options and add it to your target.

Usage

Here is a simple example:

struct ContentView: View {
    @State private var selectedCountry: Country? = nil
    let countries = Country.allCases

    var body: some View {
        TextFieldPicker(selection: $selectedCountry, options: countries)
    }
}

⚠️ Important: The selection parameter type must conform to Identifiable and CustomStringConvertible. The decription of the CustomStringConvertible is used as the display string for the picker options. In this case, country conforms to Indetifiable and CustomStringConvertible:

enum Country: String, CaseIterable, Identifiable, CustomStringConvertible {
    var id: Self { self }

    case australia = "Australia"
    case canada = "Canada"
    case egypt = "Egypt"
    case ghana = "Ghana"
    case kenya = "Kenya"
    case namibia = "Namibia"
    case morocco = "Morocco"
    case newZealand = "New Zealand"
    case southAfrica = "South Africa"
    case unitedKingdom = "United Kingdom"
    case unitedStates = "United States"

    var description: String {
        self.rawValue
    }
}

Contribution

Contributions are welcome! Please open an issue or submit a pull request if you would like to contribute to the project.

See Also

TextFieldDatePicker is a similar package but for dates. Check it out!

About

A SwiftUI package that provides a TextField with a Picker as its input view. The picker replaces the keyboard as the input view for the TextField.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages