Nikh1414
Nikh1414

Reputation: 1256

How can I create and use NSPredicate with queries in iOS's Core Data?

How can I create and use NSPredicate with queries in iOS's Core Data?

Upvotes: 2

Views: 116

Answers (1)

Robert Kang
Robert Kang

Reputation: 568

By "queries", do you mean an NSFetchRequest? If so, here is a simple example:

Say you have an entity named Car, and it has a license plate number named "licenceNumber" of NSString type.

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Car" inManagedObjectContext:yourObjectContext]];
[request setPredicate:[NSPredicate predicateWithFormat:@"licenceNumber==%@", theLicensePlateNumberYouWant]];

Saying that, you may want to spend some time reading Apple's documentation first.

Upvotes: 1

Related Questions