首页 > 解决方案 > Swift 验证函数

问题描述

你好我正在尝试创建一个名为 validate 的函数,我可以使用我创建的函数,但是当我想将它添加到屏幕时遇到问题。如何在不创建我在主页上的函数中创建的警报变量的情况下摆脱错误?

func validation(title:String,message:String,uiAlertActionTitle:String){
    
    let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.actionSheet)
    alert.addAction( UIAlertAction(title: uiAlertActionTitle, style: UIAlertAction.Style.default, handler: nil))
}

主要场所

validation(title: "Error", message: "Mail or Password is Wrong", uiAlertActionTitle: "OK")
self.present(alert, animated: true, completion: nil)

标签: swiftvalidation

解决方案


推荐阅读