Entity
としてのアクションを持つイベントがありAttribute
ます。このアクションはNSString
、iOS アプリの各イベントでコア データに保存されるものです。event.action は常に定義済みの文字列です。「仕事」「家」「昼食」
NSPredicate
最後の 5 つのアクションを取得し、最も多く実行されたアクションを取得するにはどうすればよいですか?
NSPredicate の使用に関する適切なチュートリアルはありますか?
Entity
としてのアクションを持つイベントがありAttribute
ます。このアクションはNSString
、iOS アプリの各イベントでコア データに保存されるものです。event.action は常に定義済みの文字列です。「仕事」「家」「昼食」
NSPredicate
最後の 5 つのアクションを取得し、最も多く実行されたアクションを取得するにはどうすればよいですか?
NSPredicate の使用に関する適切なチュートリアルはありますか?
次のことを試していただけませんか。リースガイドをお願いします:)
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event"
inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF IN %@", @[@"Work", @"Home", @"Lunch"]]; //contain your actions
[request setPredicate:predicate];
request.fetchLimit = 5;// retrieve the last 5 actions
NSError *error;
NSArray *yourActions = [managedObjectContext executeFetchRequest:request error:&error];
for (Event *event in yourActions)
{
// find the action that was perform the most in last 5 actions
}
フィードバックをお願いします。何が起こっているのかを知っているので、コードを編集してお手伝いします:)。
次の参照に感謝します 。NSPredicateおよびNSDateでコアデータを使用 するNSFetchedResultsControllerのfetchLimitを動的に設定する http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pUsing.html#//apple_ref / doc / uid / TP40001794-CJBDBHCB