title: How to only show value in List when it is different from previous value in SwiftUI
body: <p>I currently have a List where it alternates the date (//Climb date group) and then details (//Climb details row) from core data every row.</p>
  <p>I only want to show the date row though if it is different from the row above.</p>
  <pre><code>List{
              ForEach(climbs, id: \.self){ thisClimb in
                  let gradeText = (thisClimb as? Climb)?.grade
                  let attemptsText = (thisClimb as? Climb)?.attempts
                  let passfailText = (thisClimb as? Climb)?.passfail ?? &quot;climb string err&quot;
                  let newclimbdateText = (thisClimb as? Climb)?.climbdate
                  
                  
                  //Climb date group
                  if(oldclimbdateText != newclimbdateText){
                      HStack{
                          Spacer()
                          Text(newclimbdateText!.addingTimeInterval(600), style: .date).fontWeight(.medium)
                          Spacer()
                      }
                  }
                  
                  //Climb details row
                  HStack{
                      Text(gradesV[Int(gradeText!)])
                      Spacer()
                      Text(&quot;\(attemptsText!) attempts&quot;)
                      Spacer()
                      Text(passfailText)
                  }
  
              }.onDelete(perform: deleteClimb)
          }
  </code></pre>
  <p>The code above shows this:</p>
  <p><a href="https://i.stack.imgur.com/XTXWm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XTXWm.png" alt="iPhone screenshot" /></a></p>
  <p>So to not show the dates that are the same (see multiple Oct-18 above), what I tried to do is set a variable outside of the loop called <code>@State private var oldclimbdateText</code> and then within the if statement under &quot;//Climb date group&quot; I tried to set `oldclimbdateText = newclimbdateText``. That way on the next loop they do match does not enter the if statement.</p>
  <p>However, when I try that I get the error <code>Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols</code></p>
  <p>I'm just doing this for fun to learn. Using Xcode 12 and Swift5.</p>
  <ol>
  <li>Why do I get this error, and 2) is there a better way to get rid of these duplicate date rows?</li>
  </ol>