Bird
0
0

Which of the following is a valid way to create an NSPredicate that filters for age greater than 18?

easy📝 Conceptual Q2 of 15
iOS Swift - Local Data Persistence
Which of the following is a valid way to create an NSPredicate that filters for age greater than 18?
ANSPredicate(condition: "age > 18")
BNSPredicate("age > 18")
CNSPredicate(filter: "age > 18")
DNSPredicate(format: "age > 18")
Step-by-Step Solution
Solution:
  1. Step 1: Recall NSPredicate initializer syntax

    The correct initializer uses the format parameter with a string describing the condition.
  2. Step 2: Identify correct syntax

    Only NSPredicate(format: "age > 18") uses the correct initializer: NSPredicate(format: "age > 18").
  3. Final Answer:

    NSPredicate(format: "age > 18") -> Option D
  4. Quick Check:

    NSPredicate uses format: string [OK]
Quick Trick: Use NSPredicate(format: "condition") to create predicates [OK]
Common Mistakes:
  • Omitting 'format:' label
  • Using wrong initializer names
  • Passing condition without format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes