Baub
Baub

Reputation: 5044

Search Through Core Data

All,

I have a core data entity, CreditCard, and each entity has four values.

So, what I need to do is search through ALL of my CreditCard entities and find the one with a property pocketNum that is equal to whatever value the user puts in, and then return it so I can pull necessary values from it.

How would I do this?

Thanks, James

Upvotes: 2

Views: 281

Answers (1)

akashivskyy
akashivskyy

Reputation: 45210

Try NSFetchRequest with NSPredicate:

// 'moc' is your NSManagedObjectContext instance
// 'yourPockerNum' is what you want to find

NSEntityDescription *entity = [NSEntityDescription entityForName:@"CreditCard" inManagedObjectContext:moc]
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = entity;
request.resultType = NSDictionaryResultType;
request.predicate = [NSPredicate predicateWithFormat:@"pocketNum == %@", yourPocketNum];
NSError *error = nil;
NSArray *results = [moc executeFetchRequest:request error:&error];

// do something with results

Upvotes: 2

Related Questions