-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPedometer
More file actions
34 lines (23 loc) · 988 Bytes
/
Pedometer
File metadata and controls
34 lines (23 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import UIKit
import CoreMotion
class ViewController: UIViewController {
var Pedometer = CMPedometer()
@IBOutlet var SpeedLabel: UILabel!
@IBOutlet var DistnaceLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Pedometer.startUpdates(from: NSDate() as Date) { (data, error) in
guard let activityDate = data, error == nil else{
print("You have an error\(error)")
return
}
DispatchQueue.main.async {
print("Steps: \(activityDate.numberOfSteps)")
self.SpeedLabel.text = (activityDate.currentPace)?.stringValue
print("Distance Covered: \(activityDate.distance)")
self.DistnaceLabel.text = (activityDate.distance)?.stringValue
}
}
}
}