private func buildPredicateForMonths(monthFilter:Int16) -> NSPredicate? {
// monthsFilter is never zero as every tour has a month
let monthFilter32 : UInt32 = UInt32(monthFilter)
print("monthFilter32: \(monthFilter32)")
let predicate:NSPredicate = NSPredicate(format: "(months & %i) != 0", [monthFilter32])
print("predicate: \(predicate.description)")
return predicate
}
the output from this is:
monthFilter32: 4095 predicate: months & -2119600160 != 0
I would like the predicate to be predicate: months & 4095 != 0
I am thinking this is a result of %i but cannot find documentation on what I need here?
Thanks
CodePudding user response:
The string passed to NSPredicate expects an integer but you are passing an array so change the predicate to
let predicate = NSPredicate(format: "(months & %i) != 0", monthFilter32)