iOS/iPhone/iPad/MacOSX プログラミング, Objective-C, Cocoaなど 設定された値を元に NSPredicate を作成し、Core Data に対して検索をかけるのだが、こういう場合に NSCompoundPredicate が役に立つ。 NSCompoundPredicate Class Reference 各々の条件は必ずしも指定されるわけではないので検索条件の項目は可変となる。普通の NSPredicate を使う場合、条件の有無によって文字列の連結を使って条件を構成する必要がある。こんな感じ。 NSMutableString* fmt = [NSMutableString string]; NSMutableArray* array = [NSMutableArray array]; if (name) { [fmt appendString:
![Cocoaの日々: [Mac][iOS] NSCompoundPredicate で条件をまとめる](https://cdn-ak-scissors.b.st-hatena.com/image/square/e8a40f3a0f5f8b388a0457979a9215dcf9e4a290/height=288;version=1;width=512/http%3A%2F%2F4.bp.blogspot.com%2F_ZoUhefzk0CI%2FTS1IUNUjE2I%2FAAAAAAAAGA8%2FgoFCRGVvJSM%2Fs320%2F110112-0001.jpg)