简体   繁体   中英

Swift Beginner help : Editor placeholder in source file

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM