Contents

yusuphjoluwasen/multiselectpicker

A MultiSelect Picker for selecting multiple options, designed to feel as close as possible to the native iOS SwiftUI Picker.

Current Features

  • [x] Multi-select support
  • [x] Customizable title
  • [x] Two-way binding β€” Automatically updates selected options
  • [x] Lightweight β€” Minimal code with clean and reusable SwiftUI components.
  • [x] Light and Dark Mode
  • [x] Search β€” Add a search bar to filter options.
  • [x] Accessibility Improvements.
  • [x] Unit Tests.
  • [ ] Localizations.

Installation

You can integrate the MultiSelectPicker into your SwiftUI project using Swift Package Manager.

To install, add the following to your Package.swift dependencies:

.package(url: "https://github.com/yusuphjoluwasen/MultiSelectPicker.git", from: "1.0.0")

Usage

 MultiSelectPicker(title: "Hobbies", options: $options)

Sample Usage

import SwiftUI
import MultiSelectPicker

struct ContentView: View {
    @State var options: [FormOption] = [
        FormOption(id: "1", label: "Reading", value: "reading"),
        FormOption(id: "2", label: "Traveling", value: "traveling"),
        FormOption(id: "3", label: "Cooking", value: "cooking"),
        FormOption(id: "4", label: "Gaming", value: "gaming")
    ]

    var body: some View {
        VStack {
            MultiSelectPicker(
                title: "Hobbies",
                options: $options,
                preSelected: [
                    FormOption(id: "2", label: "Traveling", value: "traveling")
                ],
                onDone: { selected in
                    print("Selected options:", selected)
                }
            )
            .padding()
        }
    }
}

For a step-by-step guide on how to build the custom MultiSelect Picker, check out the tutorial: https://jimohyusuph.hashnode.dev/building-a-custom-multiselect-picker-in-swiftui

Run the Example

To try the component locally:

  1. Clone the repository:

```bash git clone https://github.com/yusuphjoluwasen/MultiSelectPicker.git

  1. Open the project in Xcode:

```bash cd MultiSelectPickerExample open MultiSelectPickerExample.xcodeproj

  1. Build and run the Example target to see the picker in action.

Make sure you're using Xcode 14 or later and targeting iOS 16 or above.

You can file an issue to request a feature or report a bug you come across. Thanks!

πŸ“œ License

This project is licensed under the MIT License β€” meaning you can use, modify, and distribute it freely.

Package Metadata

Repository: yusuphjoluwasen/multiselectpicker

Default branch: main

README: README.md