Skip to content

Instantly share code, notes, and snippets.

@acwright
Last active December 8, 2019 17:52
Show Gist options
  • Save acwright/2650931b0d3a4816fc37b769180e1bd8 to your computer and use it in GitHub Desktop.
Save acwright/2650931b0d3a4816fc37b769180e1bd8 to your computer and use it in GitHub Desktop.
import SwiftUI
struct StudentsView: View {
@State var predicate: NSPredicate = NSPredicate(format: "firstName contains[c] %@", "Joe")
var body: some View {
VStack {
FetchedObjects(
predicate: self.predicate,
sortDescriptors: [
NSSortDescriptor(key: "firstName", ascending: true)
])
{ (students: [Student]) in
List {
ForEach(students) { student in
Text(student.name ?? "NA")
}
}
}
Button(action: {
self.predicate = NSPredicate(format: "firstName contains[c] %@", "Mary")
}) {
Text("Find Mary")
}
}
}
}
struct ExampleView_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