Xcode: Version 14.3.1 (14E300c)
iOS: 16
预览:
Code:
import SwiftUI
import CoreDatastruct TodosSearch: View {@State private var search_title = "测试"@FetchRequest var todos_search: FetchedResults<Todo>init() {let request: NSFetchRequest<Todo> = Todo.fetchRequest()request.sortDescriptors = [NSSortDescriptor(keyPath: \Todo.title, ascending: true)]request.fetchLimit = 10_todos_search = FetchRequest(fetchRequest: request)}var body: some View {NavigationStack {VStack {TextField("Search Title", text: $search_title).padding().border(.blue)List {ForEach(todos_search) { todo inif todo.title?.contains(search_title) == true {HStack {Text(todo.title ?? "")}}}}.navigationTitle("Todos Search")}}}
}struct TodosSearch_Previews: PreviewProvider {static var previews: some View {TodosSearch()}
}