Post

Replies

Boosts

Views

Activity

filter an object array based on another
Hi, I'm new to SwiftUI and have been trying to accomplish this without success. I have the following arrays and need to filter out from the options array the items that exist in the selected array. import SwiftUI 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") { //Here I need an array of the options NOT selected } } } Any help would be greatly appreciated. Thanks
3
0
1.4k
Nov ’21