For eg, Something like:
var finalPredicate = NSPredicate(format: "")
if (screen != nil) {
screenPredicate = NSPredicate(format: "screen = %@", screen!)
finalPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [screenPredicate!])
}
if (feature != nil) {
featurePredicate = NSPredicate(format: "feature = %@", feature!)
finalPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [finalPredicate, featurePredicate!])
}
if (shouldDisplayPredicate != nil) {
shouldDisplayPredicate = NSPredicate(format: "shouldDisplay = %@", shouldDisplay!)
finalPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [finalPredicate, shouldDisplayPredicate!])
}
if (hasDisplayed != nil) {
displayPredicate = NSPredicate(format: "hasDisplayed = %@", hasDisplayed!)
finalPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [finalPredicate, displayPredicate!])
}
Is there a better way to do this where the predicates could be null or not ?
Thanks