stopDeviceMotionUpdates doesn't stop motion updates

I am new to Swift development. I am building my first WatchOS app that collects motion data. I am collecting motion data using startDeviceMotionUpdates with handler. However stopDeviceMotionUpdates doesn't stop the updates and handler goes in endless loop.

class WatchMotionManager: ObservableObject {
    let motion = CMMotionManager()
    let queue = OperationQueue()

    func startQueuedUpdates() {
        motion.deviceMotionUpdateInterval = 1.0 / 50.0
        motion.showsDeviceMovementDisplay = true
        motion.startDeviceMotionUpdates(to: self.queue, withHandler: { (data, error) in
                if let motionData = data {
                    //get data
                 }
        })
    }

    
    func stopQueuedUpdates() {
        self.motion.stopDeviceMotionUpdates()
    }

}```

If updates aren't stopping, that suggests something like (one of):
• You aren't stopping them
• They are immediately restarting
• They are starting multiple times

You need to call stopDeviceMotionUpdates()
Which you do, in stopQueuedUpdates()

So are you calling stopQueuedUpdates() correctly (you don't show the code for this)?

Do you have only one WatchMotionManager?

Thank you, I had it in view and that was creating another instance(s). With single instance of WatchMotionManager, it now stops the motion updates.

struct MotionDataView: View {



    @ObservedObject var stopWatchManager = StopWatchManager()

    

    var body: some View {

        VStack{

            Button(action: {

                if labelText == "Start" {

                    self.stopWatchManager.start()

                }

                else if labelText == "Stop" {

                    self.stopWatchManager.stop()

                }
stopDeviceMotionUpdates doesn't stop motion updates
 
 
Q