简短:我不知道如何从CMSensorRecorder中获取一个从CMensorDataList中提取CMRecordedAccelerometerData的方法。
苹果尚未提供任何文档。
也许有人对我有暗示? ;)
func startMovementDetection(){
var accDataList = self.cmSensorRecorder!.accelerometerDataFrom(self.startDate, to: NSDate()) as CMSensorDataList
CMRecordedAccelerometerData() //that's the class i want to extract from CMSensorDataList
}
好的,这里解决了这个问题:NSFastEnumeration in Swift
在Swift 3.0中,它更改为:
extension CMSensorDataList: Sequence {
public func makeIterator() -> NSFastEnumerationIterator {
return NSFastEnumerationIterator(self)
}
}
最佳答案
//First make the extension tu use enumerate in the for-in loop
extension CMSensorDataList: SequenceType {
public func generate() -> NSFastGenerator {
return NSFastGenerator(self)
}
}
//Now you can query the recorded data
func printData(){
let date = NSDate()
let recorder = CMSensorRecorder()
let sensorData: CMSensorDataList = recorder.accelerometerDataFromDate(initialDate!, toDate: date)!
for (index, data) in sensorData.enumerate() {
print(index, data)
}
}
关于Swift watchOS 2-CMSensorDataList,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31101573/