我正在尝试创建一个带有两个输入字段的警报,其中包含此应用程序的主密码。这是我的第一个应用程序。我在网上看到一个函数,想看看它是否仍然有效,但调用该函数时似乎没有弹出警报。Swift 4 中对此进行了更改吗?
func showInputDialog() {
//Creating UIAlertController and
//Setting title and message for the alert dialog
let alertController = UIAlertController(title: "Choose Master Password", message: "Enter your Master and confirm it!", preferredStyle: .alert)
//the confirm action taking the inputs
let confirmAction = UIAlertAction(title: "Enter", style: .default) { (_) in
//getting the input values from user
let master = alertController.textFields?[0].text
let confirm = alertController.textFields?[1].text
if master == confirm {
self.labelCorrect.isHidden = true
self.labelCorrect.text = master
}
}
//the cancel action doing …Run Code Online (Sandbox Code Playgroud)