我有一个数组(由NSUserDefaults填充:Defaults.arrayForKey(“onLine”)为![[String:AnyObject]])如何从SPEED中获取平均值和最大值?
我尝试在线。最大![“速度”]但没有工作
有帮助吗?
[[“LONGITUDE:”: - 122.02211045,“BEARING:”:263.41,“LATITUDE:”:37.32475565,“SPEED:”:3.76,“TIMESTAMP:”:2016-10-19T02:09:49.535Z] ,[“LONGITUDE:”: - 122.02230437,“BEARING:”:270.15,“LATITUDE:”:37.32475499,“SPEED:”:3.15,“TIMESTAMP:”:2016-10-19T02:09:54.518Z],[“ LONGITUDE:“: - 122.02249983,”BEARING:“:265.56,”LATITUDE:“:37.32475587,”SPEED:“:3.27,”TIMESTAMP:“:2016-10-19T02:09:59.516Z]]
答案 0 :(得分:0)
我用这段代码修复了自己
speedArray.append(userLocation.speed * 1.94384)
let avgSpeed = speedArray.reduce(0, combine: +) / Double(speedArray.count)
let maxSpeed = speedArray.maxElement()