你如何将UInt64.max转换为Swift中的字符串?

16 浏览
0 Comments

你如何将UInt64.max转换为Swift中的字符串?

这个问题已经在此处有答案:

在Swift中将Int转换为String

我正在尝试将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开发还是很新手,谢谢!

admin 更改状态以发布 2023年5月24日
0
0 Comments

你可以像这样做:

var str = "\(UInt64.max)"

0
0 Comments

What's wrong with:

var str = String(UInt64.max)

基本上,你应该尝试的第一件事情就是这个;在Swift中,强制类型转换是通过基于另一种类型的值来初始化所需类型来实现的。

0