How to setup ViewController in Playgrounds?

后端 未结 2 1292
南笙
南笙 2021-02-06 08:01

In swift playgrounds how do you setup a viewcontroller and use it? I\'ve done it with a UIView before but the UI gets cut when in a difference orientation so I want to try use a

2条回答
  •  爱一瞬间的悲伤
    2021-02-06 08:28

    I found that to create a viewcontroller in swift playgrounds you need this code

    import UIKit
    import PlaygroundSupport
    
    class ViewController:UIViewController{
        override func viewDidLoad() {
            super.viewDidLoad()
    
        }
    
    }
    
    let viewController = ViewController()
    PlaygroundPage.current.liveView = viewController
    PlaygroundPage.current.needsIndefiniteExecution = true
    

提交回复
热议问题