title: How can I get data from ObservedObject with onReceive in SwiftUI?
body: <p>In my SwiftUI app, I need to get data from ObservedObject each time the value change. I understood that we could do that with .onReceive? I don't understand well the documentation of Apple about it. I don't know how I can do this.</p>
  <p>My code:</p>
  <pre><code>import SwiftUI
  import CoreLocation
  
  struct Compass: View {
    
    @StateObject var location = LocationManager()
    @State private var angle: CGFloat = 0
    
    var body: some View {
      VStack {
        Image(&quot;arrow&quot;)
          .resizable()
          .aspectRatio(contentMode: .fit)
          .frame(width: 300, height: 300)
          .modifier(RotationEffect(angle: -CGFloat(self.angle.degreesToRadians)))
          .onReceive(location, perform: {
            withAnimation(.easeInOut(duration: 1.0)) {
              self.angle = self.location.heading
            }
          })
        
        Text(String(self.location.heading.degreesToRadians))
          .font(.system(size: 20))
          .fontWeight(.light)
          .padding(.top, 15)
      }
    }
  }
  
  struct RotationEffect: GeometryEffect {
    var angle: CGFloat
  
    var animatableData: CGFloat {
      get { angle }
      set { angle = newValue }
    }
  
    func effectValue(size: CGSize) -&gt; ProjectionTransform {
      return ProjectionTransform(
        CGAffineTransform(translationX: -150, y: -150)
          .concatenating(CGAffineTransform(rotationAngle: angle))
          .concatenating(CGAffineTransform(translationX: 150, y: 150))
      )
    }
  }
  </code></pre>
  <p>In my LocationManager class, I have a heading Published variable, this is the variable I want check.</p>
  <p>I need to get data each time the value of heading change to create an animation when my arrow move. For some raisons I need to use CGAffineTransform.</p>