问题描述
- 使用NSPredicate在NSArray中查找值
-
使用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" )
但是对于NSArray中带有NSSting的NSArray:
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
是什么?
时间: 2025-01-01 23:23:59