Für zB Etwas wie:Wie kombiniere ich mehrere NULL-fähige NSPredicates?
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!])
}
Gibt es einen besseren Weg, dies zu tun, wo die Prädikate null oder nicht sein könnten?
Dank
Die Karte Option ordentlich aussieht wenn auch ein wenig hart für das ungeübte (in swift) Auge zu lesen. – ofeida
@ofeida: Deshalb habe ich beide vorgestellt :) –