Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Joseph Perl](https://secure.gravatar.com/avatar/105153ec3bd525837f870e7979171b30?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Joseph Perl
877 PointsTrouble creating a function in swift.
Hello. I am trying to create a function in swift which gives the user an alert that they haven't entered a username or password when signing up. I think there may be a problem with the way I've declared the functions parameters, but am not sure. I am using version 10.3 of Xcode. I got the code I used from a video lesson, and the code worked in the video but not on my Xcode. The is:
func displayAlert(title, message) {
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) in
self.dismiss(animated: true, completion: nil)
}))
self.present(alert, animated: true, completion: nil)
}
@IBOutlet weak var email: UITextField!
@IBOutlet weak var password: UITextField!
@IBAction func signupOrLogin1(_ sender: Any) {
if email.text == "" || password.text == "" {
displayAlert("Error in form", "Please enter an email and password")
}
Most of the error messages are right to the right of the top line. They say: "Unnamed parameters must be written with the empty name '_'" They also say "use of undeclared type "message" and use of undeclared type "title". Another error to the right of the second line says: "Use of unresolved identifier 'message'".
Is this is syntax error in the top line? May of should used the word "string" somewhere when declaring the parameters. I also remember seeing the -> symbol sometimes next to functions, and am not sure if my version of the above code is only compatible with another version of swift or Xcode.
Thank you.
1 Answer
![Kevin Tanner](https://uploads.teamtreehouse.com/production/profile-photos/428082/micro_DSC_0140.jpg)
Kevin Tanner
3,385 PointsYes this is a syntax error. It looks to me like you aren't declaring the type of the parameters needed for the function. Try the code below with the types declared.
func displayAlert(title: String, message: String) {
}