Many of the simpler sensors available in iOS are exposed to us through the UIDevice
class. Responsible for keeping track of the overall device state, this class has a bunch of little features that make it actually quite fun to poke around!
If you haven't already, create a new single view Xcode project; I called mine Sensors
. Then, head over to your default view controller, and at the top of the class let's grab a reference to our current device to make it easier to get information later. Our class should start off looking like this:
class ViewController: UIViewController { let device = UIDevice.currentDevice() override func viewDidLoad() { super.viewDidLoad() } }
Now let's see what we can do!