NSMutableSetはNSSetのサブクラス。NSArrayと違い、要素の順序は考慮されない。また、同一オブジェクトを複数回登録しても無視される。
インスタンスの生成
- init
サイズを指定せずにインスタンスを生成。
+ setWithCapacity:
サイズを指定してインスタンスを生成。
– initWithCapacity:
サイズを指定してインスタンスを生成。
内容の操作
– addObject:
要素の追加。追加出来る要素はオブジェクトに限る。intはNSNumberなどでラッピングすること。
[set addObject:obj]
– filterUsingPredicate:
フィルタ。条件を満たす要素だけを残す。
NSMutableSet *mutableSet =
[NSMutableSet setWithObjects:@"One", @"Two", @"Three", @"Four", nil];
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"SELF beginswith 'T'"];
[mutableSet filterUsingPredicate:predicate];
// mutableSet contains (Two, Three)
[NSMutableSet setWithObjects:@"One", @"Two", @"Three", @"Four", nil];
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"SELF beginswith 'T'"];
[mutableSet filterUsingPredicate:predicate];
// mutableSet contains (Two, Three)
– removeObject:
要素を除去する。
– removeAllObjects
空にする。
– addObjectsFromArray:
指定したNSArray内のオブジェクトを全て追加する。
– unionSet:
指定したNSSetの要素を追加する。(和集合にする)
– minusSet:
指定したNSSetの要素を取り除く。(差集合にする)
– intersectSet:
指定したNSSetとの重複部分だけを残す。(積集合にする。)