Last active
December 8, 2019 17:52
-
-
Save acwright/2650931b0d3a4816fc37b769180e1bd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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