Get Playground to Display All Loop Results

Get playground to display all loop results

Right click on the inline quick look (the gray rounded rectangle with "4" in it). There's an option to show all the results in a list:

Value History

You can also show everything that's been printed to the console for the entire playground execution by clicking the show debug area button all the way in the bottom left corner:

Sample Image

Why is this Swift Playground Printing & Looping Twice?

Regarding override func draw(_ rect: CGRect)

This method is called when a view is first displayed or when an event
occurs that invalidates a visible part of the view.

Your line

containerView.backgroundColor = UIColor.orange

might be causing draw to get another call.

Iterating through an array only gets the first value in Swift Playground

If you're using a playground, you might need to change the view in order to see all the results..

You need to hover over the quick view display in order to find the "All Values" icon.

Sample Image


It looks like this may have changed in Xcode 7 - as @MikeMeyers mentions in the comments, you need to right click on the quick view window and select the value history option.

Sample Image

How to print to console using swift playground?

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.

Swift troubleshooting, display data in a Xcode playground?

Are you not seeing the results printed? Sounds like you may not have the Assistant Editor open. To open the assistant editor to go View -> Assistant Editor -> Show Assistant Editor. You should get a box titled "Console Output" displaying your results.

Factorial with intermediate results - Swift playgrounds - index out of range error

results is an empty array but you try to access values without appending values first.

The simplest solution might be to pre-populate your array with zeros.

var results: [Int] = Array(repeating: 0, count: n)


Related Topics



Leave a reply



Submit