One way to do this is to convert your aCondition, bCondition, etc. fields into a Dictionary. From there, you can get the keys from your dictionary, and do some simple set arithmetic:
struct Struct {
let dict : [String : String]
}
let struct1 = Struct(dict: [
"aCondition" : "a",
"bCondition" : "b",
"cCondition" : "c"
])
let struct2 = Struct(dict: [
"aCondition" : "a",
"bCondition" : "b",
"cCondition" : "nonac"
])
let structs = [struct1, struct2] //structs to be filtered
let filters : Set = ["cCondition"] //the keys to be checked for "nonac"
let filtered = structs.filter{ //filter all structs
let dict = $0.dict //get the dict of keys from the current iteration
let keys = Set(dict.keys) //make a set from the dict keys
let keysToCheck = keys.intersection(filters) //filter out to get the keys we want
let values = keysToCheck.map{dict[$0]} //get the values for the keys to check
return values.contains{$0 != "nonac"} //only keep if value != "nonac"
}
print(filtered)print(output)
aCondition,bCondition, etc. seem like quite a code smell. You could probably make those into aDictionary, making filtering quite trivialaConditionand other fields, what they do, and whether or not they can be reworked into a dictionary