【问题标题】:How can you convert UInt64.max to a String in Swift? [duplicate]如何在 Swift 中将 UInt64.max 转换为字符串? [复制]
【发布时间】:2015-08-27 17:55:00
【问题描述】:

我正在尝试将UInt64.max 转换为String

一行如:

var str: String = UInt64.max

在 XCode 中导致错误:

'UInt64' is not convertible to 'String'

再举一个例子,如下一行:

let strFromUInt: String = NSNumber(unsignedLongLong: UInt64.max)

在 XCode 中导致错误:

'NSNumber' is not convertible to 'String'

对不起,如果我在这里遗漏了什么,我对 iOS 开发还是很陌生。谢谢!

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    你可以这样做,

    var str = "\(UInt64.max)"
    

    【讨论】:

      【解决方案2】:

      有什么问题:

      var str = String(UInt64.max)
      

      基本上这是您应该尝试的第一件事;在 Swift 中,强制通过基于另一个类型的值初始化所需的类型来工作。

      【讨论】:

        猜你喜欢
        • 2017-06-06
        • 1970-01-01
        • 2018-08-31
        • 2016-03-04
        • 2016-01-21
        • 2015-03-13
        • 1970-01-01
        • 2016-08-09
        • 1970-01-01
        相关资源
        最近更新 更多