title: SwiftUI - Days of the Week Click
body: <p>I have created a simple &quot;days of the week&quot; reminder section. In that, if &quot;All&quot; is selected all the seven days have to be selected. If I click again, all days have to be unselected. But if I click on the other days only that particular item has to be selected/unselected. Toggle is an Image and DaysOfTheWeek is a Text. Any other optimum approaches are appreciated.</p>
  <pre><code>struct Task: Identifiable {
          let id = UUID()
          let name: String
          var isCompleted: Bool
      }
      
      
      @State private var tasks = [
          Task(name:NSLocalizedString(&quot;all&quot;, comment: &quot;all&quot;), isCompleted: false),
          Task(name:NSLocalizedString(&quot;sunday&quot;, comment: &quot;sunday day of week&quot;), isCompleted: false),
          Task(name:NSLocalizedString(&quot;monday&quot;, comment: &quot;monday day of week&quot;) , isCompleted: false),
          Task(name:NSLocalizedString(&quot;tuesday&quot;, comment: &quot;tuesday day of week&quot;) , isCompleted: false),
          Task(name:NSLocalizedString(&quot;wednesday&quot;, comment: &quot;wednesday day of week&quot;) , isCompleted: false),
          Task(name:NSLocalizedString(&quot;thursday&quot;, comment: &quot;thursday day of week&quot;), isCompleted: false),
          Task(name:NSLocalizedString(&quot;friday&quot;, comment: &quot;friday day of week&quot;) , isCompleted: false),
          Task(name:NSLocalizedString(&quot;saturday&quot;, comment: &quot;saturday day of week&quot;) , isCompleted: false),
          
      ]
  
  
  LazyVGrid(columns: layout, alignment: .leading, spacing: 20){
                                  ForEach($tasks) { $task in
                                      ScrollView(.vertical, showsIndicators: false) {
                                          HStack{
                                              Image(systemName: task.isCompleted ? &quot;checkmark.square.fill&quot; : &quot;square&quot;)
                                                  .foregroundColor(checked ? Color(UIColor.systemBlue) : Color.secondary)
                                                  .onTapGesture {
                                                      if task.name == &quot;all&quot; {
                                                          //select all items
                                                          if allSelected {
                                                              
                                                          }
                                                      } else {
                                                          //select only that item
                                                          
                                                      }
                                                  }
                                              
                                              Text(task.name)
                                          }
                                          
                                      }
                                  }.padding(.horizontal)
                              }
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/5DHjs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5DHjs.png" alt="App UI" /></a></p>