-2
我試圖在我的應用程序中設置Firebase,並且正在嘗試爲某人的登錄信息不正確添加一些條件。我加了user, error in
。出於某種原因,我似乎可以讓if語句正常工作。具有以下if error!=nil{
任何系標配了錯誤expected "{" after if declaration
錯誤「{預計在if語句後」
//
// RegistrationViewController.swift
// StudyBuddy
//
// Created by Basel Anani on 7/25/16.
// Copyright © 2016 StudyBuddy. All rights reserved.
//
import UIKit
import Firebase
class RegistrationViewController: UIViewController {
@IBOutlet weak var userEmailTextField: UITextField!
@IBOutlet weak var userPasswordTextField: UITextField!
@IBOutlet weak var userConfirmPasswordTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func registerButtonTapped(sender: AnyObject) {
let userEmail = userEmailTextField.text;
let userPassword = userPasswordTextField.text;
let userConfirmPassword = userConfirmPasswordTextField.text;
//Check for Empty Fields
FIRAuth.auth()?.createUserWithEmail(userEmailTextField.text!, password: userPasswordTextField.text!, completion: {
user, error in
if error !=nil{
}
else {
print("User Created")
self.login()
}
})
func login(){
FIRAuth.auth()?.signInWithEmail(userEmailTextField.text!, password: userPasswordTextField.text!, completion: {
user, error in
if error !=nil {
print("Incorrect")
}
else{
print("Login Successful")
}
})
//Save Stored Data
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);
if (userEmail!.isEmpty) {
displayMyAlertMessage("All fields are required");
return;
}
if (userPassword!.isEmpty) {
displayMyAlertMessage("All fields are required");
return;
}
if (userConfirmPassword!.isEmpty) {
displayMyAlertMessage("All fields are required");
return;
}
if userPassword != userConfirmPassword {
displayMyAlertMessage("Passwords do not match");
}
}
}}}
如果這個答案是正確的,那麼這是對編譯器編寫者技能的控制。空白只應該是消除歧義的必要條件,這裏沒有歧義。 – EJP