[英]Swift3: How can I add a String type value to an UI Label in which a calculated value has already been pasted?
When doing so I get the Error Code:这样做时,我收到错误代码:
Cannot assign value of type '(String, String)' to type 'String?'无法将 '(String, String)' 类型的值分配给类型 'String?'
As you can see below, I have already converted the Numbers to String values which didn't help.正如您在下面看到的,我已经将数字转换为字符串值,但没有帮助。
Ultimately I want to have an UI Label which displays a value + String depending on a switch function.最终我想要一个 UI 标签,它根据开关功能显示一个值 + 字符串。
The Value is going to switch Units and the UI Label should say ( 256 Days or 3.5 hours and for the last example not 0.14 days)值将切换单位,UI 标签应显示(256 天或 3.5 小时,最后一个示例不是 0.14 天)
Assigning the Units when printing inti the XCode Console is easy.在 XCode 控制台打印时分配单位很容易。 What I would need is to copy the Console Output ( Target Output) and then paste it into a UI Label, if the other method doesnt work.如果其他方法不起作用,我需要的是复制控制台输出(目标输出),然后将其粘贴到 UI 标签中。
Here the Code :这里的代码:
switch Differenz {切换差异{
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 )
}
could you try this out?你能试试这个吗?
var usedTimeLabel = "seconds" //reassign this value when doing switch
Output.text = "\(Differenz) \(usedTimeLabel)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.