First, open Xcode and create a new project. The app we're making will be a single-view application. Select the Single-View Application icon then proceed by clicking Next.
Now give your app a name in the Product Name text field. Once you've chosen a product name, make sure Use Core Data, Include Unit Tests and Include UI Tests are all unchecked before you click Next to save your project on your computer.
Before we start, check out the project's file hierarchy on the left side of the project window. The View Controller file is where you'll be entering your code and the Main.storyboard file is where you'll be adding UI to your app.
In the ViewController.swift file, we'll begin by importing the CoreMotion framework to our project. Below the
import UIKit we will add:
CoreMotion framework gives us the ability to receive and handle accelerometer data and other motion data such as gyroscope and barometer data for our app.
Next, we'll gain access to our acceleration data, so we'll create an instance of CMMotionManager to access it in the ViewController class.
CMMotionManager provides services like accelerometer data, rotation-rate data, magnetometer data, and other device-motion data.
Before we go further, let's set up a user interface so that we can see our accelerometer sensor data.