ios – How can I go Binding in SwiftUI preview?

0
16


I handed the motionManager of my app from ContentView to SecondView and it really works effective, however i do not know how one can go it within the preview of my SecondView, it needs argument kind Binding<CMMotionManager>

ContentView

import SwiftUI
import CoreMotion

struct ContentView: View {
    
    @State non-public var motionManager = CMMotionManager()
    let queue = OperationQueue()
    @State non-public var roll = Double.zero
    
    var physique: some View {
        NavigationView {
            VStack {
                
                Textual content("Roll is: (roll)")
                    .font(.largeTitle)
                
                NavigationLink {
                    SecondView(motionManager: $motionManager)
                } label: {
                    Textual content("Change View")
                }
            }
            .onAppear {
                //Detect system movement
                self.motionManager.startDeviceMotionUpdates(to: self.queue) { (information: CMDeviceMotion?, error: Error?) in
                    guard let information = information else {
                        print("Error: (error!)")
                        return
                    }
                    let perspective: CMAttitude = information.perspective
                    
                    DispatchQueue.essential.async {
                        self.roll = perspective.roll
                    }
                }
            }
        }
    }
}

SecondView

import SwiftUI
import CoreMotion

struct SecondView: View {
    @Binding var motionManager: CMMotionManager
    
    var physique: some View {
        Textual content("Hey, World!")
    }
}

struct SecondView_Previews: PreviewProvider {
    static var previews: some View {
        SecondView(motionManager: Binding<CMMotionManager>) <-- //What ought to i go right here??
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here