简体   繁体   English

Swift3:如何向已粘贴计算值的 UI 标签添加字符串类型值?

[英]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.

相关问题 如何忽略已在swift 3中计算出的UITextField的值? - how to ignore a value of a UITextField that has already been calculated in swift 3? 有字符串Url,但URL有“ \\ /”。如何获取字符串中每个正确的值,如数组类型swift3 - Got string Url but the url have “\/”.How to get each correct value in string like array type swift3 如何将Label设置为Float,以便我可以拥有Label描绘滑块值(Xcode Swift) - How do set a Label to type Float so I can have the Label portray slider value (Xcode Swift) Swift3中的“无法转换类型的值”错误 - “Cannot convert value of type” error in Swift3 Swift3循环字典增加价值 - Swift3 loop dictionary to add value iOS在Swift3中添加多个可选值 - iOS Add multiple optional value in Swift3 如何在swift3中从Any获取字符串 - How can I get String from Any in swift3 我如何从单个json值中提取字符串并将其快速附加到我的标签中(使用alamofire) - how can I fetch a string from a single json value and append it to my label in swift (using alamofire) Swift3错误:无法将类型'()'的值分配给类型[[customObject]? - Swift3 error: Cannot assign value of type '()' to type '[customObject]?' 'String' 类型的值在 Swift 3 中没有成员 'stringByRemovingPercentEncoding - Value of type 'String' has no member 'stringByRemovingPercentEncoding in Swift 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM