I would do something like this:
struct Option: Decodable, Hashable {
var userCode: String
var optType: String
var optValue: String
}
struct Selected: Decodable, Hashable {
var userCode: String
var tradeCode: String
var optType: String
var optValue: String
}
struct ContentView: View {
@State var options = [
Option(userCode: "1", optType: "Emotions", optValue: "Sad"),
Option(userCode: "1", optType: "Emotions", optValue: "Happy"),
Option(userCode: "1", optType: "Emotions", optValue: "Angry"),
Option(userCode: "1", optType: "Emotions", optValue: "Calm")
]
@State var selected = [
Selected(userCode: "1", tradeCode: "1", optType: "Emotions", optValue: "Sad"),
Selected(userCode: "1", tradeCode: "1", optType: "Emotions", optValue: "Happy")
]
var body: some View {
Button("Options Not Selected") {
let notSelectedOptions = options.filter() { !isOptionInSelected(for: $0) }
print(notSelectedOptions) // Just to check
// Here I need an array of the options NOT selected
}
}
func isOptionInSelected(for option: Option) -> Bool {
for select in selected {
if option.userCode == select.userCode && option.optType == select.optType && option.optValue == select.optValue {
return true
}
}
return false
}
}