开发者

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 whate开发者_如何学Cver value the user puts in, and then return it so I can pull necessary values from it.

How would I do this?

Thanks, James


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜