title: SwiftUI: How to change @Published object value. Changing a value of a published variable is not working
body: <p>I'm doing a page which consists of 5 Options with radio buttons. When we tap on an option the colour of the element should change. I'm fetching those options from API response. I'm using the MVVM model. I am attaching the code below. </p>
  
  <p>What I'm struggling with is when I change a boolean value, it is not changing!!!</p>
  
  <p><strong>View Model code</strong> </p>
  
  <pre><code>import Foundation
  import Combine
  
  class DCListViewModel: ObservableObject {
      @Published var DCList = [DCViewModel]()
  
      init() {
          fetchDcs()
      }
  
      func fetchDcs() {
          ARMServices().getAllDc { (dcArr) in
              if let dcArr = dcArr {
                  for dc in dcArr{
                      self.DCList.append(DCViewModel(dc: dc, isSelected: false))
                  }
              }
          }
      }
  }
  
  
  class DCViewModel {
      var id = UUID()
      var dcStruct: DC
      var isSelected: Bool
  
      init(dc: DC, isSelected: Bool) {
          self.dcStruct = dc
          self.isSelected = isSelected
      }
  
      var url: String {
          return self.dcStruct.url  ?? "empty URL"
      }
  
      var dc: String {
          return self.dcStruct.dc ?? "empty dc name"
      }
  }
  </code></pre>
  
  <p><strong>View Page Code</strong></p>
  
  <pre><code>struct SelectTableView: View {
  
      var body: some View {
          NavigationView {
  
                  VStack {
                      DCListView(dcList: self.dcListVM.DCList)
                          .padding(.horizontal)
                  }
              .navigationBarTitle("Select the Data Centre")
          }
      }
  }
  
  
  struct DCListView: View{
      var dcList: [DCViewModel]
  
      init(dcList: [DCViewModel]) {
          self.dcList = dcList
      }
  
      var body: some View {
          ForEach(self.dcList, id: \.id) { dc in
              Button(action: {
                  print("Tapped")
                  dc.isSelected.toggle()
              }){
                  ZStack {
                      RoundedRectangle(cornerRadius: 8)
                          .stroke(dc.isSelected ? Color.init("borderSelected"): Color.init("border"))
                          .frame(height: 56)
                          .foregroundColor(.clear)
  
                      HStack {
                          Text(dc.dc)
                              .font(.custom("Montserrat", size: 16))
                              .fontWeight(.medium)
                              .foregroundColor(dc.isSelected ? Color.init("borderSelected") : .white)
                              .padding()
  
                          Spacer()
  
                          ZStack {
                              Circle()
                                  .stroke(dc.isSelected ? Color.init("borderSelected") : Color("circleBorder"))
                                  .frame(width: 18, height: 18)
                                  .padding()
  
                              Circle()
                                  .frame(width: 10, height: 10)
                                  .foregroundColor(dc.isSelected ? Color.init("borderSelected"): Color.clear)
                          }
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/KjsyJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KjsyJ.png" alt="The page looks like this"></a></p>