0

coredataから最新の30レコードを取得したい、NSPredicateを使いたい:現在

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:managedContext];
[request setEntity:entity];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"((from == %@) AND (to == %@) )OR((from == %@) AND (to == %@))",from, to,to ,from];
[request setPredicate:predicate];


NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedContext
                                        executeFetchRequest:request
                                        error:&error] mutableCopy];

メソッドの追加方法

4

1 に答える 1

3

ソート記述子を使用して正しい順序にし、フェッチ制限を 30 に設定します。

NSSortDescriptor* fromSortDescriptor = [[NSSortDescriptor alloc]
                            initWithKey:@"from" ascending:YES];
[request setSortDescriptors:@[fromSortDescriptor]];
[request setFetchLimit:30];
于 2013-01-22T12:04:33.660 に答える