2

NSArray私だけで値を見つけることができます:

NSArray *arr = [NSArray arrayWithObjects:@"299-1-1", @"299-2-1", @"299-3-1", @"399-1-1", @"399-2-1", @"399-3-1", @"499-1-1", @"499-2-1", @"499-3-1", nil];
NSString *search = @"299";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@",[NSString stringWithFormat:@"%@", search]];
NSArray *array = [arr filteredArrayUsingPredicate: predicate];
NSLog(@"result: %@", array);

Found Result予想通り :

 result: (
 "299-1-1",
 "299-2-1",
 "299-3-1"
 )

しかし、一緒にいるためNSArrayNSArrayNSString

NSArray *arr = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"299-1-1", nil],[NSArray arrayWithObjects:@"399-1-1", nil],[NSArray arrayWithObjects:@"499-1-1", nil], nil];

ここには何がありますかpredicate syntax?????

4

3 に答える 3

14

ネストされた配列を検索するには、述語で「ANY」演算子を使用できます。

NSArray *arr = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"299-1-1", nil],[NSArray arrayWithObjects:@"399-1-1", nil],[NSArray arrayWithObjects:@"499-1-1", nil], nil];
NSString *search = @"299";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY SELF CONTAINS %@", search];
NSArray *array = [arr filteredArrayUsingPredicate: predicate];
NSLog(@"result: %@", array);

出力:

(
    (
        「299-1-1」
    )
)
于 2013-04-17T13:14:22.997 に答える
-1
NSArray *arr = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"299-1-1", nil],[NSArray arrayWithObjects:@"399-1-1", nil],[NSArray arrayWithObjects:@"499-1-1", nil], nil];
NSString *search = @"299";
NSMutableArray *filteredArray = [[NSMutableArray alloc] init];
for (NSArray *array in arr) {
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self CONTAINS %@",search];
    if([array filteredArrayUsingPredicate:predicate].count)
    {
        [filteredArray addObject:[array filteredArrayUsingPredicate:predicate]];
    }
}
NSLog(@"%@", filteredArray);
于 2013-04-17T12:31:02.747 に答える