-
SwiftUI iOS15_108 - Searchable viewsSwiftUI 100 레시피/New IOS 15 2022. 7. 1. 17:46
struct CustomerListView: View{
let customers: [String]
var body: some View{
List(customers, id:\.self){
customer in
Text(customer)
}
}
}
struct LearnSearchable: View {
let names = ["Alex", "John", "Mary", "James", "Steve"]
@State private var text: String = ""
var body: some View {
NavigationView{
CustomerListView(customers: names)
}.searchable(text: $text){
ForEach(names.filter{$0.hasPrefix(text)}, id: \.self){ name in
Text(name)
} .onSubmit(of: .search){
//perform the search
}
}
}
}
struct LearnSearchable_Previews: PreviewProvider {
static var previews: some View {
LearnSearchable()
}
}
'SwiftUI 100 레시피 > New IOS 15' 카테고리의 다른 글
SwiftUI iOS15_110 - 흐림(Blur) 처리 (0) 2022.07.01 SwiftUI iOS15_109 - Swift Actions (0) 2022.07.01 SwiftUI iOS15_107 - TimeLine (0) 2022.07.01 SwiftUI iOS15_106 - refresh (0) 2022.07.01 SwiftUI iOS15_105 - AsyncImage (0) 2022.07.01