Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print to console using swift playground?

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

like image 835
Arian Faurtosh Avatar asked Jun 02 '14 20:06

Arian Faurtosh


People also ask

How do I open the console in Swift?

Just hover your mouse pointer over the value evaluation area (pane next to your coding area) and click on the plus sign to open the output pane. If you have closed the console output in the output pane, then click anywhere in the coding area and press enter. You will get your console output back.

How do I display print in Xcode?

Press ⇧⌘Y or choose View > Debug Area > Show Debug Area to show the console output (or ⇧⌘C / Activate Console). Usually, this window will open automatically when your program produces output (this is controlled by the Behaviors section of Xcode's Preferences).

What is the difference between Swift playground and Xcode?

Xcode and Swift are both software development products developed by Apple. Swift is a programming language used to create apps for iOS, macOS, tvOS, and watchOS. Xcode is an Integrated Development Environment (IDE) that comes with a set of tools that helps you build Apple-related apps.


2 Answers

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.

like image 77
rickster Avatar answered Sep 29 '22 09:09

rickster


you need to enable the Show Assistant Editor:

enter image description here

like image 28
Kumar KL Avatar answered Sep 29 '22 07:09

Kumar KL