本文主要是介绍iOS: NSArray的方法filteredArrayUsingPredicate:,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- (NSArray *)filteredArrayUsingPredicate:(NSPredicate *)predicate
用谓语筛选数组,返回一个新数组。
example
NSMutableArray *array = |
[NSMutableArray arrayWithObjects:@"Nick", @"Ben", @"Adam", @"Melissa", nil]; |
|
NSPredicate *bPredicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'a'"]; |
NSArray *beginWithB = [array filteredArrayUsingPredicate:bPredicate]; |
// beginWithB contains { @"Adam" }. |
|
NSPredicate *sPredicate = [NSPredicate predicateWithFormat:@"SELF contains[c] 'e'"]; |
[array filterUsingPredicate:sPredicate]; |
// array now contains { @"Nick", @"Ben", @"Melissa" } |
这篇关于iOS: NSArray的方法filteredArrayUsingPredicate:的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!