i want create a sign up with firebase and swift 4, first a view controller asks me the email, after entering the email, I click on next, and another view controller will ask me for the password, then click on register. How do I save the first Viewcontroller's email, pass it to the second ViewController for the password, and then send it all to firebase? sorry for my english. In practice it must work like the instagram sign up.
This is the code of the first view controller:
import Foundation
import Firebase
import FirebaseAuth
import UITextField_Shake
internal class SignUpSegue0 : UIViewController {
@IBOutlet weak var labelwrongpass: UILabel!
@IBOutlet weak var Emailsign: UITextField!
func isValidEmail(testStr:String) -> Bool {
print("validate emilId: \(testStr)")
let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegEx)
let result = emailTest.evaluate(with: testStr)
return result
}
@IBAction func Nextsign1(_ sender: UIButton) {
guard let email = Emailsign.text else { return }
Auth.auth().fetchProviders(forEmail: email, completion: {
(providers, error) in
if error != nil {
print("Email disponibile")
self.labelwrongpass.text = "Email inserita correttamente"
self.labelwrongpass.textColor = UIColor.green
} else if providers != nil {
print("L'email inserita è già presente")
self.labelwrongpass.text = nil
self.labelwrongpass.text = "L'email inserita è già presente"
self.Emailsign.shake(10,withDelta: 5.0)
}
})
}
override func viewDidLoad() {
super.viewDidLoad()
let userDefaults = UserDefaults.standard
let Emailsign = userDefaults.string(forKey: "emailsign")
}
}
If you want to pass the value from one VC to another you shouldn't use UserDefaults. You may as well use a global variable if you do that !
You create a Custom ViewController
In the second VC create a property called email.
Then in the first Vc
let vc2 = SecondViewController() vc2.email = theEmail
Push / Seque to vc2
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.