Xcode Playground Timeline empty

前端 未结 2 1785
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-19 09:31

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

2条回答
  •  时光说笑
    2021-01-19 10:14

    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.

提交回复
热议问题