Swiftpack.co -  thislooksfun/SwiftlySearch as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
thislooksfun/SwiftlySearch
A small, lightweight UISearchController wrapper for SwiftUI
.package(url: "https://github.com/thislooksfun/SwiftlySearch.git", from: "v1.2.5")

THIS PROJECT IS OBSOLETE

iOS 15 introduced .searchable(), which is an official search bar implementation for SwiftUI. As such this project is now obsolete. I will continue to keep it around as a polyfill for apps targeting <iOS 15, but it will no longer be actively developed and you should switch to the new system as soon as you can. Thank you all for your support, and happy coding!

SwiftlySearch

A small, lightweight UISearchController wrapper for SwiftUI

Installation

Manual:

Update your Package.swift file:

let package = Package(
  ...,

  dependencies: [
    .package(
      url: "https://github.com/thislooksfun/SwiftlySearch.git",
      from: "1.0.0"),

    ...
  ],

  ...
)

In Xcode:

  1. Go to File > Swift Packages > Add Package Depencency...
  2. Enter https://github.com/thislooksfun/SwiftlySearch as the URL
  3. Select your desired versioning constraint
  4. Click Next
  5. Click Finish

Usage

import SwiftlySearch

struct MRE: View {
  let items: [String]

  @State
  var searchText = ""

  var body: some View {
    NavigationView {
      List(items.filter { $0.localizedStandardContains(searchText) }) { item in
        Text(item)
      }.navigationBarSearch(self.$searchText)
    }
  }
}

Known issues:

(#12) NavigationLinks inside the resultContent don't work. This is a limitation of the UIKit/SwiftUI interaction, and thus out of my hands. If you require a seperate view for displaying search results you can use a workaround like shown below:

struct ContentView: View {
    @State
    var searchText: String = ""

    var body: some View {
        NavigationView {
            ZStack {
                if searchText.isEmpty {
                    NormalView()
                } else {
                    SearchResultsView(text: searchText)
                }
            }
            .navigationBarSearch($searchText)
        }
    }
}

struct NormalView: View {
    var body: some View {
        Text("Some view")
    }
}

struct SearchResultsView: View {
    var text: String

    var body: some View {
        VStack {
            Text("You searched for \(text)")
            NavigationLink(destination: Text(text)) {
                Text("Let's go!")
            }
        }
    }
}

GitHub

link
Stars: 181
Last commit: 6 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

v1.2.5
1 week ago

Changelog:

  • Deprecate SwiftlySearch on iOS 15+

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API