@RatKill
In the following code:
import UIKit
class RegisterPageViewController: UIViewController {
@IBOutlet weak var repeatPasswordTextField: UITextField!
@IBOutlet weak var userPassportTextField: UITextField!
@IBOutlet weak var userEmailTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func registerButtoTapped(sender: AnyObject) {
let userEmail = userEmailTextField.text
let userPassword = userPassportTextField.text
let userRepeatPassword = repeatPasswordTextField.text
if userEmail.isEmpty || userPassword.isEmpty || userRepeatPassword.isEmpty {
displayMyAlertMessage("all fields are requirede"); // ⚠
return;
}
if(userPassword != userRepeatPassword) {
displayMyAlertMessage("Password do not match"). // ⚠
return;
}
NSUserDefaults.standardUserDefaults().setObject(userEmail, forKey: "user Email")
NSUserDefaults.standardUserDefaults().setObject(userPassword, forKey: "userPassword")
NSUserDefaults.standardUserDefaults().synchronize();
var myAlert = UIAlertController(title: "Alert", message: "Registration is sucesfull. Thank you!", preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default){
action in
self.dismissViewControllerAnimated(true, completion: nil)
}
func displayMyAlertMessage(userMessage:String) {
var myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil);
myAlert.addAction(okAction)
self.presentViewController(myAlert, animated: true, completion: nil);
}
}
As the func is defined inside another func, it must be defined before use.
But if the func displayMyAlertMessage were defined at the top level of the class, it could be declared after use. That's due how the compiler processes the code.
Interesting discussion here:
https://forums.swift.org/t/improve-nested-functions-visibility-or-order-dependency/33935/8
But anyway, correcting the error is so easy that I advise not to bother too much. That's the limits of the compiler which is already very smart.
Note: in the previous code, the label for argument was missing in the func use.