0

Detailと の2 つの属性を持つエンティティがtitleありtextます。それらの多くがあり、多くは複製されています。これは、関係として別のエンティティの多くのインスタンスに割り当てられているためです。

text特定の に対してすべての一意の が必要titleです。まず、適切な述語を作成します。

NSPredicate *predicate = [NSPredicate predicateWithFormat:
   @"title = %@", aTitle]; 

結果の配列を一意のtextエントリのみに減らすにはどうすればよいですか?

どうにかして myfetchedResultsControllerを使用してこれらをテーブル ビューに表示できますか、それともデータ ソースとして別の配列を作成する必要がありますか? このようなメモリの問題に遭遇する可能性があることを恐れています。

ご協力いただきありがとうございます!

4

1 に答える 1

0

次のようなものは、valueForKeypath で機能する可能性があります。

    NSDictionary * dict00 = [NSDictionary dictionaryWithObject:@"hat" forKey:@"key"];
    NSDictionary * dict01 = [NSDictionary dictionaryWithObject:@"bag" forKey:@"key"];
    NSDictionary * dict02 = [NSDictionary dictionaryWithObject:@"shirt" forKey:@"key"];
    NSDictionary * dict03 = [NSDictionary dictionaryWithObject:@"hat" forKey:@"key"];
    NSDictionary * dict04 = [NSDictionary dictionaryWithObject:@"hat" forKey:@"key"];

    NSMutableArray * array = [NSMutableArray arrayWithCapacity:5];
    [array addObject:dict00];
    [array addObject:dict01];
    [array addObject:dict02];
    [array addObject:dict03];
    [array addObject:dict04];

    NSArray * deDupedArray = [array valueForKeyPath:@"@distinctUnionOfObjects.key"];
    NSLog(@"%@",deDupedArray);
于 2012-04-09T01:25:34.623 に答える