2017-09-24 1 views
2

복잡한 NSCompoundPredicate을 신속하게 만들려고하는데, 어떻게해야할지 모르겠다.신속한 복잡한 NSCompoundPredicate 만들기 3

5 개의 술어 (p1, p2, p3, p4, p5)가 있다고 가정합니다. 나는 조건 아래에 구현하려는 :

compound1 = (p1 AND p2 AND p3) // NSCompoundPredicate(type: .and, 
           //subpredicates: predicates) 
compound2 = (p4 AND p5) // NSCompoundPredicate(type: .and, 
         //subpredicates: predicates) 
compound3 = (compound1 OR compound2) // problem is here 

fetchRequest.predicate = compound3 

NSCompoundPredicate는 두 번째 인수가 원하는하지 않는 NSPredicates의 배열을 가져옵니다의로. 가장 좋은 솔루션은 무엇입니까? NSPredicate에서

답변

4

NSCompoundPredicate 상속 그러므로 가 subpredicate 같은 다른 화합물 술어 첫번째 단계에서 생성되는 화합물의 조건을 전달할 수

let compound1 = NSCompoundPredicate(type: .and, subpredicates: [p1, p2, p3]) 
let compound2 = NSCompoundPredicate(type: .and, subpredicates: [p4, p5]) 
let compound3 = NSCompoundPredicate(type: .or, subpredicates: [compound1, compound2]) 

fetchRequest.predicate = compound3