Post

Replies

Boosts

Views

Activity

Reply to Accelerometer data not printing correctly.
Hi everyone. I spent all day an all night messing with the settings, and I finally figured it out. For anyone getting the same problem, I did the following: Click the label. Go to the right triangle that says "Show the size inspector." Under layout, click "auto resizing mask." Then, select horizontal arrow and vertical arrow. Thanks everyone who took the time to read this!!!
1w
Reply to Xcode won't execute code?
I rewrote the code without errors but the screen is just blank and white. struct ContentView: View { var body: some View { } } import CoreMotion class MyViewController: UIViewController { let motionManager = CMMotionManager() func startAccelerometer() { if motionManager.isAccelerometerAvailable { motionManager.accelerometerUpdateInterval = 0.1 // 10 updates per second motionManager.startAccelerometerUpdates(to: .main) { (data, error) in guard let accelerometerData = data else { return } let x = accelerometerData.acceleration.x let y = accelerometerData.acceleration.y let z = accelerometerData.acceleration.z // Process the x, y, and z acceleration values here print("X: \(x), Y: \(y), Z: \(z)") } startAccelerometer() } } } #Preview { ContentView() }
1w
Reply to Xcode won't execute code?
I wrote the following code above the code in my first post.. struct ContentView: View { var body: some View { Button("Tap Me") { // Action to perform when the button is tapped print("Button was tapped!") startAccelerometer() } } } The error message says "Cannot find 'startAccelerometer' in scope" Thanks again for the help!
1w
Reply to Xcode won't execute code?
Thank you for your help! I put this code above the code already mentioned. inline-code struct ContentView: View { var body: some View { Button("Tap Me") { // Action to perform when the button is tapped print("Button was tapped!") startAccelerometer() } } func myFunction() { // Your Swift code to be executed print("myFunction was called!") } } `inline-code` I get an error message saying: " Cannot find 'startAccelerometer' in scope"
1w