Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Swift游乐场中获得弹出对话框_Swift_Swift Playground - Fatal编程技术网

如何在Swift游乐场中获得弹出对话框

如何在Swift游乐场中获得弹出对话框,swift,swift-playground,Swift,Swift Playground,我想知道如何在Swift操场中弹出一个对话框(是的,必须在操场中)。我已经尝试了以下代码(直接从AppleDevs站点) 但是,无论我怎么做,selftag总是会抛出一个错误。有人能帮我吗 import UIKit let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert) alert.addAction(UIAlertAction(title: N

我想知道如何在Swift操场中弹出一个对话框(是的,必须在操场中)。我已经尝试了以下代码(直接从AppleDevs站点)

但是,无论我怎么做,
self
tag总是会抛出一个错误。有人能帮我吗

import UIKit
let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert) 
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in 
    NSLog("The \"OK\" alert occured.")
}))
self.present(alert, animated: true, completion: nil)

需要从视图控制器显示警报。这意味着它将出现在助理编辑器内的模拟器中:

例如:

import UIKit
import PlaygroundSupport

let alert = UIAlertController(title: "My Alert", message: "This is an alert.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
    NSLog("The \"OK\" alert occured.")
}))
let v = UIViewController()
PlaygroundPage.current.liveView = v
v.present(alert, animated: true, completion: nil)

创建游乐场文件时选择单一视图在哪里?“单一视图”在任何地方都没有列出