NSCompoundPredicateクラス
apple(mac)
解説
継承 | NSPredicate : NSObject |
準拠 | NSCoding (NSPredicate) |
NSCopying (NSPredicate) | |
NSObject (NSObject) | |
フレームワーク | /System/Library/Frameworks/Foundation.framework |
使用可能 | Mac OS X v10.4以降,iOS 3.0以降 |
定義 | NSCompoundPredicate.h |
概要
作成
ANDで接続した新しいNSPredicateオブジェクトを作成するには(+ andPredicateWithSubpredicates:)メソッドを使用します。NOTにした新しいNSPredicateオブジェクトを作成するには(+ notPredicateWithSubpredicate:)を使用します。
ORで接続した新しいNSPredicateオブジェクトを作成するには(+ orPredicateWithSubpredicates:)メソッドを使用します。
"*"を含んで、かつ"-"を含まない要素を取り出すNSPredicateオブジェクトの作成
#pragma mark NSPredicate notPredicateWithSubpredicate: -(void)method003 { NSArray *strings = [NSArray arrayWithObjects:@"b-a*a", @"aaa",@"ba*a",@"b-bb",@"bbb",@"b-b*b",@"a*a", nil]; NSMutableArray *predArray = [[NSMutableArray alloc] initWithCapacity:3]; NSPredicate *aPred = [NSPredicate predicateWithFormat:@"SELF contains '-'"]; NSPredicate *notPred = [NSCompoundPredicate notPredicateWithSubpredicate:aPred]; [predArray addObject:notPred]; NSPredicate *bPred = [NSPredicate predicateWithFormat:@"SELF contains '*'"]; [predArray addObject:bPred]; NSPredicate *cPred = [NSCompoundPredicate andPredicateWithSubpredicates:predArray]; NSArray *bResult = [strings filteredArrayUsingPredicate:cPred]; NSLog(@"%s %@",__FUNCTION__,[bResult description]); //=>("ba*a","a*a") NSLog(@"%s %@", __FUNCTION__,[cPred predicateFormat]); //=>(NOT SELF CONTAINS "-") AND SELF CONTAINS "*" }
結合タイプとNSPredicateオブジェクトの配列で、NSCompoundPredicateオブジェクトを初期化するには(– initWithType:subpredicates:)メソッドを使用します。
結合タイプ
NSNotPredicateType
NOT結合
NSAndPredicateType
AND結合
NSOrPredicateType
OR結合
AND結合のNSCompoundPredicateオブジェクトを作成するサンプル
#pragma mark NSPredicate initWithType:subpredicates: -(void)method005 { NSArray *strings = [NSArray arrayWithObjects:@"b-a*a", @"aaa",@"ba*a",@"b-bb",@"bbb",@"b-b*b",@"a*a", nil]; NSMutableArray *predArray = [[NSMutableArray alloc] initWithCapacity:3]; NSPredicate *aPred = [NSPredicate predicateWithFormat:@"SELF contains '-'"]; [predArray addObject:aPred]; NSPredicate *bPred = [NSPredicate predicateWithFormat:@"SELF contains '*'"]; [predArray addObject:bPred]; NSCompoundPredicate *cPred = [[NSCompoundPredicate alloc] initWithType:NSAndPredicateType subpredicates:predArray]; //NSNotPredicateType = 0, //NSAndPredicateType, //NSOrPredicateType, NSArray *bResult = [strings filteredArrayUsingPredicate:cPred]; NSLog(@"%s %@",__FUNCTION__,[bResult description]); //=>("b-a*a","ba*a","b-bb","b-b*b","a*a") NSLog(@"%s %@", __FUNCTION__,[cPred predicateFormat]); //=>SELF CONTAINS "-" OR SELF CONTAINS "*" }
情報の取得
結合タイプを得るには(– compoundPredicateType)メソッドを使用します。結合するNSPredicateオブジェクトの配列を得るには(– subpredicates)メソッドを使用します。
適合するプロトコル
メソッド
Constructors
+ andPredicateWithSubpredicates
+ notPredicateWithSubpredicate
+ orPredicateWithSubpredicates
– initWithType:subpredicates
Getting Information About a Compound Predicate
サブクラス化の注意
引数
参照
メソッド