简体   繁体   中英

How to present an UIViewController in Swift Playgrounds for macOS?

I have Swift Playgrounds v3.2 downloaded from AppStore on my macOS device. I would like to present an instance of the UIViewController class in an empty project. I tried to present it like in the Xcode playground with PlaygroundPage.current.liveView = vc but it doesn't worked.

import PlaygroundSupport

let vc = UIViewController()

PlaygroundPage.current.liveView = vc

PlaygroundPage.current.needsIndefiniteExecution = true

Make sure you import UIKit

Then set the view of the UIViewController to liveView like so

PlaygroundPage.current.liveView = vc.view

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM