Swift3:如何将一个String类型值添加到已经粘贴了计算值的UI Label中?

时间:2017-12-27 04:45:17

标签: swift switch-statement xcode6

这样做时我得到错误代码:

  

无法将类型'(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 )


}

1 个答案:

答案 0 :(得分:0)

你可以尝试一下吗?

var usedTimeLabel = "seconds" //reassign this value when doing switch
Output.text = "\(Differenz) \(usedTimeLabel)"