title: Smoothly speed up rotation in SwiftUI
body: <p>I would like to smoothly accelerate the rotation speed of a shape in a SwiftUI application then slow it back down again to fixed speed. First I tried toggling the animation speed using a <code>@State</code> <code>Bool</code> as I would any other property (e.g. <code>.speed(speedUp ? 5.0 : 1.0)</code>), but I suppose animation properties themselves are not themselves animatable. I've also tried using an <code>AnimatableModifier</code> to no effect:</p>
  
  <pre class="lang-swift prettyprint-override"><code>import SwiftUI
  
  struct SpeedModifier: AnimatableModifier {
      var speed: Double
      var animatableData: Double {
          get { speed }
          set { speed = newValue }
      }
  
      func body(content: Content) -&gt; some View {
          return content.animation(
                  Animation
                      .linear(duration: 5.0)
                      .speed(speed)
                      .repeatForever(autoreverses: false)
              )
      }
  }
  
  struct SwiftUIView: View {
      @State var isRotating = false
      @State var speedUp = false
      var body: some View {
          Rectangle()
              .frame(width: 200, height: 200)
              .rotationEffect(.degrees(isRotating ? 360 : 0))
              .modifier(SpeedModifier(speed: speedUp ? 5.0 : 1.0))
              .onAppear {
                  self.isRotating.toggle()
                  DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
                      self.speedUp.toggle()
                  }
              }
      }
  }
  
  struct SwiftUIView_Previews: PreviewProvider {
      static var previews: some View {
          SwiftUIView()
      }
  }
  
  </code></pre>