4

I am trying to use the timeline assistant editor for playground in xcode version 7.3.1, it is always empty. Timeline assistant editor

I think the error is from xcode, however from search it doesn't look like anyone got the same error so i am confused.

mediumkuriboh
  • 57
  • 1
  • 10
  • Could you be more specific? – Abizern Aug 14 '16 at 09:59
  • As of Xcode 8 and Swift 3, you need to import the PlaygroundSupport module to render to the timeline. I gave a more detailed post on how to achieve this below! – Simon Nov 30 '16 at 19:50
  • Possible duplicate of [How to print to console using swift playground?](http://stackoverflow.com/questions/24003092/how-to-print-to-console-using-swift-playground) – rickster Nov 30 '16 at 23:55
  • The OP has some confusion between question text and screenshot. From the screenshot, it's clear that the question is actually about how to see `print` output — which actually has nothing to do with the Timeline UI. That makes this question a duplicate of [How to print to console using swift playground?](http://stackoverflow.com/q/24003092/957768) – rickster Nov 30 '16 at 23:57

2 Answers2

2

To display the result of print you need to open the "debug area" by going to menu

View > Debug Area > Show Debug Area

or click on the button in the lower left part:

enter image description here

enter image description here

To display the timeline graph, you could use XCPCaptureValue:

import XCPlayground

var x = 0
for i in 0...10 {
    x += i
    print(x)
    XCPCaptureValue("Value for x", value: x)   
}

enter image description here

but XCPCaptureValue has been deprecated and won't be available in the future (there's no available replacement).

The alternative is to display the graph inline by clicking on the "+" button on the right:

enter image description here

Do a right click on the graphs and you can choose to display value history instead:

enter image description here

Community
  • 1
  • 1
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • After i imported XCPlayground, and used XCPCaptureValue function, the timeline worked. i was thinking that the graphs are implicit in the timeline. – mediumkuriboh Aug 14 '16 at 12:13
  • Oops I forgot to mention importing XCPlayground in my answer, edited, thanks. Note that if you upgrade to Xcode 8 you will have to import "PlaygroundSupport" instead of "XCPlayground". – Eric Aya Aug 14 '16 at 12:15
0

I was just getting started in Playgrounds myself, and came across the same problem of not being able to print to Timeline.

This Medium article explains how to show or render things in the timeline as of Xcode 8 and Swift 3. Basically, you have to create a view and assign it to the PlaygroundPage.current.liveView:

import UIKit
import PlaygroundSupport 

let contentView = UIView(frame: CGRect(x: 0, y: 0, width: 320.0, height: 600.0))
contentView.backgroundColor = UIColor.white

PlaygroundPage.current.liveView = contentView

Afterwards, you can add anything to your contentView to be displayed in the timeline. The PlaygroundPage.current.liveView can receive any UIView, such as UILabel, UITextField, etc.

However, sometimes the created view defaults to a black background, so you have to remember to set the .backgroundColor to UIColor.white to see it's info/child views.

Simon
  • 141
  • 1
  • 7