A small, lightweight UISearchController wrapper for SwiftUI
Update your Package.swift
file:
let package = Package(
...,
dependencies: [
.package(
url: "https://github.com/thislooksfun/SwiftlySearch.git",
from: "1.0.0"),
...
],
...
)
- Go to File > Swift Packages > Add Package Depencency...
- Enter
https://github.com/thislooksfun/SwiftlySearch
as the URL - Select your desired versioning constraint
- Click Next
- Click Finish
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)
}
}
}