这两种获取indexPath.row字符串值的方式有什么区别?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var newString: String = String(indexPath.row)
var newString2: String = indexPath.row.description)
}
最佳答案
description
属性用来表示any的内容NSObject
或任何实现 Printable
的类/结构/枚举字符串格式的协议(protocol),尽管在 Int
的情况下( indexPath.row
是 Int
)它只返回数字的字符串值,你不应该用它来转换 Int
至 String
.有可能在 Swift 的 future 版本中 description
属性将返回类似“Int:[value]”的内容。
你应该使用 String(indexPath.row)
相反。
关于ios - 获取 indexPath.row 的字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29108199/