Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created September 13, 2022 02:41
Show Gist options
  • Select an option

  • Save sturdysturge/9a6664b149f7e1b4687b82cb9ddd01ed to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/9a6664b149f7e1b4687b82cb9ddd01ed to your computer and use it in GitHub Desktop.
import SwiftUI
@available(iOS 16.0, *)
struct ContentView: View {
@State private var query: String = ""
static let ids: [IdentifiableData] = (1...10).map { IdentifiableData(index: $0) }
@State var displayedIds: [IdentifiableData] = Self.ids
var body: some View {
NavigationView {
VStack {
Text("This one won't work")
DismissButton()
List(displayedIds) { id in
Section("Item \(id.index)") {
Text("\(id.id.uuidString)")
DismissButton()
}
}
.searchable(text: $query, prompt: "Search")
.submitLabel(.search)
.onSubmit(of: .search) {
displayedIds = Self.ids.filter { $0.id.uuidString.contains(query) }
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment