Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如果跑步者在健身跟踪应用程序中处于配速状态,我如何跟踪?_Ios_Xcode_Macos_Swift3_Swift Playground - Fatal编程技术网

Ios 如果跑步者在健身跟踪应用程序中处于配速状态,我如何跟踪?

Ios 如果跑步者在健身跟踪应用程序中处于配速状态,我如何跟踪?,ios,xcode,macos,swift3,swift-playground,Ios,Xcode,Macos,Swift3,Swift Playground,我正在经历苹果“应用程序开发与Swift”iBook的挑战,在完成第2.2课-功能中的健身应用程序时遇到了障碍。我想不出一个好的公式来跟踪用户是否在配速上。我仍然是一个呆子,到目前为止,这是我所想到的,显然不能准确地跟踪速度 func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) { if (currentDistance < 0.

我正在经历苹果“应用程序开发与Swift”iBook的挑战,在完成第2.2课-功能中的健身应用程序时遇到了障碍。我想不出一个好的公式来跟踪用户是否在配速上。我仍然是一个呆子,到目前为止,这是我所想到的,显然不能准确地跟踪速度

func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) {

        if (currentDistance < 0.50 * totalDistance && currentTime > 0.40 * goalTime)     {
            print("You've got to push it just a bit harder!")
    }
    else {
            print("Keep it up!")
    }
}
pacing(currentDistance: 1, totalDistance: 10, currentTime: 8, goalTime:60)
func起搏(currentDistance:Double,totalDistance:Double,currentTime:Double,goalTime:Double){
如果(当前距离<0.50*总距离和当前时间>0.40*目标时间){
打印(“你得再用力一点!”)
}
否则{
打印(“坚持下去!”)
}
}
起搏(当前距离:1,总距离:10,当前时间:8,目标时间:60)
书中的挑战告诉你要做到以下几点:
您的健身追踪应用程序将帮助跑步者保持配速以达到目标。编写一个名为packing的函数,该函数采用四个双参数,分别为currentDistance、totalDistance、currentTime和goalTime。你的函数应该计算出用户是否在达到或超过目标时间的配速上。如果是,请打印“保持速度!”,否则请打印“您必须再用力一点!”

因为我们知道距离=速度*时间,所以这里您想知道当前速度是多少,并基于此打印相应的消息,以便您可以尝试以下操作:

func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) {

        let goalSpeed = totalDistance / goalTime
        let currentSpeed = currentDistance / currentTime

        if (currentSpeed < goalSpeed)     {
                print("You've got to push it just a bit harder!")
        }
        else {
                print("Keep it up!")
        }
}
pacing(currentDistance: 1, totalDistance: 10, currentTime: 8, goalTime:60)
func起搏(currentDistance:Double,totalDistance:Double,currentTime:Double,goalTime:Double){
让目标速度=总距离/目标时间
让currentSpeed=当前距离/当前时间
if(当前速度<目标速度){
打印(“你得再用力一点!”)
}
否则{
打印(“坚持下去!”)
}
}
起搏(当前距离:1,总距离:10,当前时间:8,目标时间:60)

非常感谢,回答得很好。我不可能要求更好的。