这样做时,我得到错误代码:
无法将类型'(String,String)'的值赋值为'String?'
正如您在下面所看到的,我已经将Numbers转换为String值,这些值没有帮助。
最终我想要一个UI标签,根据开关功能显示值+ String。
Value将切换单位,UI标签应该说(256天或3.5小时,最后一个例子不是0.14天)
在打印到XCode控制台时分配单位很容易。我需要的是复制控制台输出(目标输出),然后将其粘贴到UI标签中,如果其他方法不起作用。
这里的代码:
切换差异{
case 1...9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 : print (Differenzstring,"Years")
case 0.0027...0.99 : print ( Differenz*365, "Days ")
case 0.000114...0.00269 : print (Differenz * 365*24,"Hours")
case 0.0000019...0.0001139 : print (Differenz * 365 * 24 * 60, "Minutes" )
case 0.000000000001 ... 0.00000189 : print (Differenz * 365 * 24 * 60 * 60,"Seconds")
case 0...0: print ( "Time (almost) stops")
default : print ( "Calculation failed" )
}
// Units not inegrated yet, Result will therefore be in Years perfect would be the Cosnole Output, provided by the Switch Statement also being pasted into "Output Label"
Output.text = String ( Differenz )
}
你能尝试一下吗?
var usedTimeLabel = "seconds" //reassign this value when doing switch
Output.text = "\(Differenz) \(usedTimeLabel)"