Skip to content

Instantly share code, notes, and snippets.

@acwright
Last active November 23, 2019 03:51
Show Gist options
  • Save acwright/d4384f9e7f516adc7d034c0796ac34f5 to your computer and use it in GitHub Desktop.
Save acwright/d4384f9e7f516adc7d034c0796ac34f5 to your computer and use it in GitHub Desktop.
@FetchRequest
import SwiftUI
struct StudentsView: View {
@FetchRequest(
entity: Student.entity(),
sortDescriptors: [],
predicate: NSPredicate(format: "name = %@", "Joe")
) var students: FetchedResults<Student>
var body: some View {
List {
ForEach(students) { student in
Text(student.name ?? "No Name")
}
Button(action: {
// How do I search for students with the first name Mary?
}) {
Text("Find Mary")
}
}
}
}
struct StudentsView_Previews: PreviewProvider {
static var previews: some View {
StudentsView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment