Reputation:
I am a beginner at Swift. I am trying to implement a sign in and signup page for a new app I am creating. I have looked at other questions asked that are similar to mine but couldn't resolve so I am asking for your help. I must admit I am following an outdated tutorial which may not be compatible with the current Xcode.
@IBAction func signup(_ sender: Any) {
if username.text == "" || password.text == "" {
var alert = UIAlertController(title: "Error in form", message: "Please enter a username and password", preferredStyle: <#T##UIAlertControllerStyle#>.Alert)
alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
}))
self.presentViewController(alert, animated: true, completion: nil)
}
}
Error messages I am receiving
1) Static member 'Alert' cannot be used on instance of type 'UIAlertControllerStyle'
2) Editor placeholder in source file
Can anyone offer any guidance? I can preview the page and it looks good but the build fails.
Thanks in advance.
Upvotes: 0
Views: 1528
Reputation: 318854
The errors are on this line:
var alert = UIAlertController(title: "Error in form", message: "Please enter a username and password", preferredStyle: <#T##UIAlertControllerStyle#>.Alert)
Note the placeholder text after preferredStyle:
. Remove that and put the proper value:
var alert = UIAlertController(title: "Error in form", message: "Please enter a username and password", preferredStyle: .Alert)
Unrelated to your issue, do not call self.dismiss...
in the alert action. The alert will be dismissed automatically when the user taps on any button.
Upvotes: 1