I am making an apple watch app where it gets the accelerometer data from a date to another date. By using this code:
@IBAction func start() {
WKInterfaceDevice.currentDevice().playHaptic(WKHapticType.Start)
let startDate = NSDate()
NSUserDefaults.standardUserDefaults().setObject(startDate, forKey: "StartDate")
}
@IBAction func stop() {
WKInterfaceDevice.currentDevice().playHaptic(WKHapticType.Stop)
let endDate = NSDate()
let startDate = NSUserDefaults.standardUserDefaults().objectForKey("StartDate") as! NSDate
printData(startDate, endDate: endDate)
}
Then when I got to export the data using the function printData() which this is the code for that function
func printData(startDate: NSDate, endDate: NSDate) {
let recorder = CMSensorRecorder()
let list: CMSensorDataList = recorder.accelerometerDataFromDate(startDate, toDate: endDate)!
for (index, data) in list.enumerate() {
print(index, data)
}
}
For the enumeration I have an extension and here is the code for the extension:
extension CMSensorDataList: SequenceType {
public func generate() -> NSFastGenerator {
return NSFastGenerator(self)
}
}
When I press the stop button the app crashes. I got all of my code from this question(Swift watchOS 2 - CMSensorDataList) but it doesn't work on my device. Does anyone know what is happening?