99

I have been following the Apple Guide for their new language swift, but I don't understand why the bar on the right is only showing "Hello, playground" and not "Hello, world". Can someone explain why the println isn't being printed on the right?

// Playground - noun: a place where people can play

import Cocoa

var str = "Hello, playground"

println("Hello, world");

enter image description here

Binarian
  • 12,296
  • 8
  • 53
  • 84
Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115
  • Related question: [How can I print to console in Swift Playgrounds on iPad?](https://stackoverflow.com/q/55397751/2641242) – jraufeisen Mar 28 '19 at 12:34

7 Answers7

133

In Xcode 6.3 and later (including Xcode 7 and 8), console output appears in the Debug area at the bottom of the playground window (similar to where it appears in a project). To show it:

  • Menu: View > Debug Area > Show Debug Area (⌘⇧Y)

  • Click the middle button of the workspace-layout widget in the toolbar

    workspace layout widget

  • Click the triangle next to the timeline at the bottom of the window

    triangle for console

Anything that writes to the console, including Swift's print statement (renamed from println in Swift 2 beta) shows up there.


In earlier Xcode 6 versions (which by now you probably should be upgrading from anyway), show the Assistant editor (e.g. by clicking the little circle next to a bit in the output area). Console output appears there.

Community
  • 1
  • 1
rickster
  • 124,678
  • 26
  • 272
  • 326
  • Showing the assistant editor worked... but what is the bar on the right? That isn't the console output? – Arian Faurtosh Jun 02 '14 at 20:57
  • 8
    It's the "results sidebar" — it shows the value of the expression on its line... vaguely equivalent to the variables view in the Xcode debugger. – rickster Jun 02 '14 at 21:00
  • In my case, there is no "console" window inside the assistant? It's just an empty grey screen. Println output doesn't go anywhere? – Kokodoko Jul 23 '14 at 18:51
  • Xcode 6.4 does not print anything to the debug area, its only in the assistant editor. – Andrew Aug 15 '15 at 19:57
72

you need to enable the Show Assistant Editor:

enter image description here

Kumar KL
  • 15,315
  • 9
  • 38
  • 60
13

Just Press Alt + Command + Enter to open the Assistant editor. Assistant Editor will open up the Timeline view. Timeline by default shows your console output.

Additionally You can add any line to Timeline view by pressing the small circle next to the eye icon in the results area. This will enable history for this expression. So you can see the output of the variable over last 30 secs (you can change this as well) of execution.

Siv Ragav
  • 395
  • 1
  • 12
11

You may still have trouble displaying the output in the Assistant Editor. Rather than wrapping the string in println(), simply output the string. For example:

for index in 1...5 {
    "The number is \(index)"
}

Will write (5 times) in the playground area. This will allow you to display it in the Assistant Editor (via the little circle on the far right edge).

However, if you were to println("The number is \(index)") you wouldn't be able to visualize it in the Assistant Editor.

adr
  • 362
  • 1
  • 11
  • 1
    But why is that? Is that a bug or why should you then even use the **println** command? – OscarWyck Jun 25 '14 at 14:56
  • 4
    I believe it's a bug actually. Sometimes, if I restart Xcode, I am able to see the output from `println` – adr Jun 25 '14 at 21:18
  • Yes, I have restarted xcode and it seems to work now. Must be a bug! Thanks! – Kirk Jul 29 '14 at 13:47
2

As of Xcode 7.0.1 println is change to print. Look at the image. there are lot more we can print out. enter image description here

user2511630
  • 3,214
  • 2
  • 17
  • 15
0

move you mouse over the "Hello, playground" on the right side bar, you will see an eye icon and a small circle icon next it. Just click on the circle one to show the detail page and console output!

0

for displaying variables only in playground, just mention the variable name without anything

let stat = 100

stat // this outputs the value of stat on playground right window

jai
  • 1