Xcode Playground Timeline empty

ぐ巨炮叔叔 提交于 2019-12-01 19:39:39

问题


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.


回答1:


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:

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)   
}

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:

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




回答2:


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.



来源:https://stackoverflow.com/questions/38940858/xcode-playground-timeline-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!