views:

33

answers:

1

Hi, everyone.

It may looks like a newbie question, but I really am. I try to fetch only first object from Core data. But I try to figure out how could I done this?

For example, it may have 100 object in Core data for specific entity. I just need the first one. Could you give me your advice?

+1  A: 

See Fetch limits

NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setFetchLimit:1];
diciu
actually, since he's only looking for the first entity, wouldn't it be [request setFetchLimit:1]?
Shawn Craver
:-) i'll edit my answer. thanks.
diciu
You would also want to include a sort descriptor as well, right? Since core data does note guarantee any order, correct?
ctshryock
Thank for all of you, guys. I can use this solution for my project now. :)
Teerasej