Recall & Review
beginner
What is an NSPredicate in Swift?
An NSPredicate is a way to filter collections or Core Data fetch requests by defining conditions that items must meet. Think of it like a filter that only lets through items matching certain rules.
Click to reveal answer
beginner
How do you create a predicate to find names starting with "A"?
You create it like this:
NSPredicate(format: "name BEGINSWITH[c] %@", "A"). This means it looks for names starting with 'A', ignoring case.Click to reveal answer
beginner
What is NSSortDescriptor used for?
NSSortDescriptor tells Swift how to sort a list of items. For example, you can sort by a property like 'age' in ascending or descending order.
Click to reveal answer
intermediate
How do you sort an array of people by age descending using NSSortDescriptor?
You create a sort descriptor like this:
NSSortDescriptor(key: "age", ascending: false) and use it to sort the array.Click to reveal answer
intermediate
Why use predicates and sort descriptors together?
Using predicates filters your data to only what you want, and sort descriptors organize that filtered data in the order you want. Together, they help you get exactly the right data, nicely ordered.
Click to reveal answer
What does NSPredicate do in Swift?
✗ Incorrect
NSPredicate is used to filter data by specifying conditions.
Which of these is the correct way to create a predicate to find items where 'age' is greater than 18?
✗ Incorrect
The predicate format "age > 18" filters for ages greater than 18.
What does NSSortDescriptor(key: "name", ascending: true) do?
✗ Incorrect
It sorts items by the 'name' property in ascending order.
How can you combine multiple sort descriptors?
✗ Incorrect
Multiple NSSortDescriptors can be combined in an array to sort by multiple keys.
Which is true about predicates and sorting?
✗ Incorrect
Predicates filter data by conditions; sorting arranges data order.
Explain how you would filter a list of contacts to only those whose names start with 'J' and then sort them by last name ascending.
Think about how to write the predicate format and then create a sort descriptor.
You got /4 concepts.
Describe the difference between NSPredicate and NSSortDescriptor and how they work together in data handling.
Imagine filtering a list first, then arranging it.
You got /3 concepts.