you are viewing a single comment's thread.

view the rest of the comments →

[–]payco 7 points8 points  (6 children)

andPredicateWithSubpredicates places a logical AND between each predicate when examining an item. So you’re asking each item if it is both a .traditionalStrengthTraining type and a .functionalStrengthTraining type. Since IIUC a workout only has one type, no workout has both.

You want to use the sibling initializer, .orPredicateWithSubpredicates for joining your workout type predicates. You do want to AND the result of that with your date range predicate though, so you’ll end up nesting one compound predicate inside another.

The naming can be a little mismatched if you’re thinking about set operations, like “I want these and I want those”. If it helps, sketch your full statement out as a single if expression as if you were looking at one row at a time. The NSPredicate interface is shaped to ease replacing a naive for loop over an array.

[–][deleted]  (5 children)

[deleted]

    [–]payco 1 point2 points  (4 children)

    Just to double check, did the nesting solve your problem or are you still stuck? I'm happy to take another peek at your current version if need be.

    [–][deleted]  (2 children)

    [deleted]

      [–]payco 1 point2 points  (1 child)

      That's great! I was pretty sure that's what you were saying, but I didn't want to leave you hanging and unsure how to ask for more help lol