Bird
0
0

Which of the following is the correct syntax to create an NSPredicate filtering for names equal to "John"?

easy📝 Syntax Q12 of 15
iOS Swift - Local Data Persistence
Which of the following is the correct syntax to create an NSPredicate filtering for names equal to "John"?
ANSPredicate(format: "name == 'John'")
BNSPredicate(format: "name = 'John'")
CNSPredicate(format: "name equals 'John'")
DNSPredicate(format: "name === 'John'")
Step-by-Step Solution
Solution:
  1. Step 1: Recall NSPredicate format syntax

    NSPredicate uses format strings with == for equality comparison.
  2. Step 2: Identify correct equality operator

    == is the correct operator; = or === are invalid in NSPredicate format.
  3. Final Answer:

    NSPredicate(format: "name == 'John'") -> Option A
  4. Quick Check:

    Use == for equality in NSPredicate [OK]
Quick Trick: Use double equals (==) for equality in predicates [OK]
Common Mistakes:
  • Using single equals (=) instead of double (==)
  • Using === which is not valid in NSPredicate
  • Writing 'equals' as a word instead of operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes