Ios 获取indexPath.row的字符串值

Ios 获取indexPath.row的字符串值,ios,uitableview,swift,Ios,Uitableview,Swift,这两种获取indexPath.row字符串值的方法有什么区别 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var newString: String = String(indexPath.row) var newString2: String = indexPath.row.descript

这两种获取indexPath.row字符串值的方法有什么区别

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var newString: String = String(indexPath.row)
    var newString2: String = indexPath.row.description)
}
description属性用于以字符串格式表示任何NSObject或实现可打印协议的任何类/结构/枚举的内容,尽管在Int indexPath.row为Int的情况下,它只返回数字的字符串值,但您不应使用它将Int转换为字符串。在未来版本的Swift description属性中,可能会返回类似Int:[value]的内容。 您应该改用StringindexPath.row。

description属性用于以字符串格式表示任何NSObject或任何实现可打印协议的类/struct/enum的内容,尽管在Int-indexPath.row为Int的情况下,它只返回数字的字符串值,但不应使用它将Int转换为字符串。在未来版本的Swift description属性中,可能会返回类似Int:[value]的内容。 您应该改用StringindexPath.row

将indexPath转换为字符串并存储为indexValue变量


将indexPath转换为字符串并存储为indexValue变量。

对于Int,除了使用。对许多对象的描述有一些非常不同的结果,并且不一定是值的字符串转换。此外,如果可以推断类型,则无需在swift中定义变量:String=。对于Int,没有区别,但对许多对象使用.description会产生一些非常不同的结果,并且不会始终是值的字符串转换。此外,如果可以推断类型,则不需要在swift中定义变量:String=。
var indexValue :String = String(format: "%d", indexPath.row)