Error showing a UIAlertView in swift

This is what I have used to make an alert popup in swift.

let myAlert = UIAlertView(title: "Invalid Login",     
message: "Please enter valid user name",       
delegate: nil, cancelButtonTitle: "Try Again") 
myAlert.show()

Swift 5

You should do it this way:

let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Button", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)

Even though UIAlertView is depreciated in iOS8, you can get away with using it but not through it's init function. For example:

    var alert = UIAlertView()
    alert.title = "Title"
    alert.message = "message"
    alert.show()

Atleast this is the only way so far I've been able to successfully use an UIAlertView. I'm unsure on how safe this is though.