我很好奇我是否可以直接在我的界面中使用println,这将减少我向客户展示原型的时间,而无需编写特定函数来迭代复杂的数据。换句话说,我想要实现的是这样的:
textView.text = println(object)
我很欣赏任何奇妙的方法!问候。
toString()
函数返回的内容与println()
打印到控制台的内容相同:
let xs = [1, 2, 3, 4, 5]
let xsString = toString(xs)
// xsString == "[1, 2, 3, 4, 5]"
在您的情况下,textView.text = toString(object)
会做您想做的事。
您也可以
使用 .description
let myArray = [1, 2, 3, 4, 5]
let myArrayDescription = myArray.description // "[1, 2, 3, 4, 5]"
let myDateDescription = NSDate().description // "2015-01-13 18:57:15 +0000"
// you can also use it with current locale
let myDateDescriptionWithLocale = NSDate().descriptionWithLocale(NSLocale.currentLocale())! // "Tuesday, January 13, 2015 at 4:59:07 PM Brasilia Summer Time"