object-c in_array
判断的三种方式:
//
// main.m
// learning
//
// Created by xiaozi on 13-12-8.
// Copyright (c) 2013年 xiaozi. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSString* extsStr = @"php,js,py";
NSArray* extsArr = [extsStr componentsSeparatedByString:@","];
// 是否在数组中 {{{
NSPredicate* rule1 = [NSPredicate predicateWithFormat:@"SELF IN %@", extsArr];
BOOL result1 = [rule1 evaluateWithObject:@"txt"];
NSLog(@"%d", result1);
// }}}
// {{{
NSPredicate* rule2 = [NSPredicate predicateWithFormat:@"SELF CONTAINS %@", @"js"];
// 数组包含
BOOL result2 = [rule2 evaluateWithObject:extsArr];
NSLog(@"%d", result2);
// }}}
// 数组过滤
BOOL result3 = [[extsArr filteredArrayUsingPredicate:rule2] count];
NSLog(@"%d", result3);
}
return 0;
}
本人是iOS开发者,来看看大神写的博客 受益匪浅!