Yank
Yank

Reputation: 748

Is that possible of using println directly as a String output in Swift?

I am very curious if I can use println directly in my interface , this will reduce my time of showing prototype to customer without write specific function to iterating through a complex data. In another word ,what I want achieve is something like :

textView.text = println(object)

I am appreciate for any fantastic approaches ! Regards.

Upvotes: 1

Views: 51

Answers (2)

Leo Dabus
Leo Dabus

Reputation: 236340

You can also use .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"

Upvotes: 1

Nate Cook
Nate Cook

Reputation: 93276

The toString() function returns the same thing that a println() would print to the console:

let xs = [1, 2, 3, 4, 5]
let xsString = toString(xs)
// xsString == "[1, 2, 3, 4, 5]"

In your case, textView.text = toString(object) would do what you want.

Upvotes: 3

Related Questions