🔴 Let's Build Twitter with SwiftUI (iOS 15, Xcode 13, Firebase, SwiftUI 3.0)
@Published var searchText = ""
var searchableUsers: [UserModel] {
if searchText.isEmpty {
return users
} else {
let lowercasedQuery = searchText.lowercased()
return users.filter({$0.userName.contains(lowercasedQuery) || $0.fullName.lowercased().contains(lowercasedQuery)})
}
}
import SwiftUI
struct SearchBar: View {
@Binding var text: String
var body: some View {
HStack {
TextField("Search...", text: $text)
.padding(8)
.padding(.horizontal, 24)
.background(Color(.systemGray6))
.cornerRadius(8)
.overlay(
HStack {
Image(systemName: "magnifyingglass")
.foregroundColor(.gray)
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
.padding(.leading, 8)
}
)
}
.padding(.horizontal, 4)
}
}