我想在Playground玩UIAlertController.是否有可能从XCPlaygroundPage获取ViewController - 能够调用presentViewController?
您可以设置实时查看到你的窗口后提出,以避免该警告.
import UIKit import PlaygroundSupport PlaygroundPage.current.needsIndefiniteExecution = true let window = UIWindow() let viewController = UIViewController() window.rootViewController = viewController window.makeKeyAndVisible() let alert = UIAlertController(title: "title here", message: "message here", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "action here", style: .default, handler: nil)) viewController.present(alert, animated: true, completion: nil) PlaygroundPage.current.liveView = window
结果: