开发者

A fetch request can only fetch one entity at a time, right?

Is that true? Or could I fetch multiple entities at once? If so,开发者_StackOverflow中文版 how would that look like?

(Guess: No. NSFetchRequest asks for one and only one entity)


NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyEntities" inManagedObjectContext:[self context]];
[request setEntity:entity]; 

There is the request set up, calling:

NSMutableArray *mutableFetchResults = [[[[self context] executeFetchRequest:request error:&error] mutableCopy] autorelease];

Will return an array of all my MyEntities persistet by Core Data.

You can pass the request sortDescriptors or predicates to filter and sort the return values, but the value is always an array.

It is a bit tricky, but extremely useful.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜