Swift “错误”;无法调用类型为';字符串';具有类型为';(Int64?'&引用;带零凝聚算子

Swift “错误”;无法调用类型为';字符串';具有类型为';(Int64?'&引用;带零凝聚算子,swift,int64,Swift,Int64,我得到一个错误“无法使用类型为“(Int64?”)的参数列表调用类型为“String”的初始化器”,使用nil合并运算符 stackoverflow上也有类似的问题,但它们没有提供我需要的解决方案 注释中有错误的我的代码: let cell = tableView.dequeueReusableCell(withIdentifier: "countCell", for: indexPath) cell.textLabel?.text = String(detailItem?.count) ??

我得到一个错误“无法使用类型为“(Int64?”)的参数列表调用类型为“String”的初始化器”,使用nil合并运算符

stackoverflow上也有类似的问题,但它们没有提供我需要的解决方案

注释中有错误的我的代码:

let cell = tableView.dequeueReusableCell(withIdentifier: "countCell", for: indexPath)
cell.textLabel?.text = String(detailItem?.count) ?? "1" // Cannot invoke initializer for type 'String' with an argument list of type '(Int64?)'

let cell = tableView.dequeueReusableCell(withIdentifier: "countCell", for: indexPath)
cell.textLabel?.text = String(Int(detailItem?.count)) ?? "1" // Cannot invoke initializer for type 'Int' with an argument list of type '(Int64?)'

let cell = tableView.dequeueReusableCell(withIdentifier: "countCell", for: indexPath)
cell.textLabel?.text = String(Int(detailItem!.count)) ?? "1" // Cannot invoke initializer for type 'Int' with an argument list of type '(Int64?)'

let cell = tableView.dequeueReusableCell(withIdentifier: "countCell", for: indexPath)
cell.textLabel?.text = String(detailItem?.count ?? "1") // Cannot convert value of type 'String' to expected argument type 'Int64'
你可以简单地做

let int64Value: Int64 = 123
let str = String(int64Value)
编辑:

由于
detailItem?.count
可选的
,因此需要在将其传递给
字符串
初始值设定项之前将其展开。可以使用nil合并运算符展开并提供默认值,即

cell.textLabel?.text = String(detailItem?.count ?? 1)


关于
let string=string(intValue)
–至于其他整数和浮点类型呢?我尝试了let string=string(int64Value),但得到了一个错误。这将是问题中有用的信息,最好是a。
int64Value
的值是多少?请尝试我在答案中添加的代码。另外,把你得到的错误贴出来。那是行不通的。我试过了。它在我的游乐场上起作用,但不起作用。我试过了。添加了不起作用的代码。用相关的解决方案更新了代码。看起来效果不错。错误消息消失了。Xcode仍在构建中。我的Mac mini现在真的很慢。太好了,如果答案有效,请接受。快乐编码。。
let tmp = Int64(10)
print(String(tmp))