0

I want to implement this query in xcode

Select * from people where age >40 and mariageState = false

I can retrive all records but could not narrow my search with the conditions of age and mariagestae

How can I use NSPredicate or NSFetchRequest to implement such query?

1 Answer 1

1

It's almost the same syntax

let request = NSFetchRequest(entityName:"people")    
request.predicate = NSPredicate(format: "age > 40 AND mariageState == FALSE")

You can easily add sort descriptors

request.sortDescriptors = [NSSortDescriptor(key: "firstName", ascending: true), 
                           NSSortDescriptor(key: "age", ascending: false)]
Sign up to request clarification or add additional context in comments.

2 Comments

I was thinking of something completely different. My issue is solved. Thank you
How can i combine it with sortDescriptor? For example by firstName ascending and age descending.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.