Bird
0
0

What does an NSPredicate do in Swift when working with arrays?

easy📝 Conceptual Q11 of 15
iOS Swift - Local Data Persistence
What does an NSPredicate do in Swift when working with arrays?
ARemoves duplicates from the array
BSorts the array in ascending or descending order
CAdds new items to the array
DFilters the array to include only items matching a condition
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of NSPredicate

    An NSPredicate is used to specify conditions to filter collections like arrays.
  2. Step 2: Differentiate filtering from sorting

    Filtering means selecting items that meet a condition, while sorting changes order.
  3. Final Answer:

    Filters the array to include only items matching a condition -> Option D
  4. Quick Check:

    Predicate = Filter [OK]
Quick Trick: Predicate means filter, not sort or add [OK]
Common Mistakes:
  • Confusing predicate with sorting
  • Thinking predicate adds or removes items
  • Assuming predicate changes order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes