Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thislooksfun/SwiftlySearch
A small, lightweight UISearchController wrapper for SwiftUI
https://github.com/thislooksfun/SwiftlySearch
combine combine-framework deprecated deprecated-api deprecated-library deprecated-repo deprecated-repository ios ios-14 ios-library ios13 obsolete obsoleted swift swift-5 swift-library swiftui
Last synced: about 1 month ago
JSON representation
A small, lightweight UISearchController wrapper for SwiftUI
- Host: GitHub
- URL: https://github.com/thislooksfun/SwiftlySearch
- Owner: thislooksfun
- License: mit
- Archived: true
- Created: 2020-06-13T17:09:36.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-06-08T02:53:41.000Z (over 3 years ago)
- Last Synced: 2024-10-03T20:15:49.014Z (3 months ago)
- Topics: combine, combine-framework, deprecated, deprecated-api, deprecated-library, deprecated-repo, deprecated-repository, ios, ios-14, ios-library, ios13, obsolete, obsoleted, swift, swift-5, swift-library, swiftui
- Language: Swift
- Homepage:
- Size: 59.6 KB
- Stars: 223
- Watchers: 8
- Forks: 19
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-swiftui-libraries - SwiftlySearch - A small, lightweight UISearchController wrapper for SwiftUI (Search / Content)
README
# THIS PROJECT IS OBSOLETE
iOS 15 introduced [`.searchable()`][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 \ 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
```swift
import SwiftlySearchstruct 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](https://github.com/thislooksfun/SwiftlySearch/issues/12)) `NavigationLink`s 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:
```swift
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: Stringvar body: some View {
VStack {
Text("You searched for \(text)")
NavigationLink(destination: Text(text)) {
Text("Let's go!")
}
}
}
}
```[searchable]: https://developer.apple.com/documentation/swiftui/form/searchable(text:placement:)