-2

I want to pass the value "Email" from one VC to another when I press the button. So 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 email of first ViewController and pass it to the second ViewController? And then send email of first vc and password of second vc to firebase? sorry for my english. In practice it must work like the instagram sign up.

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 }

    if Emailsign.text == "" {
        self.labelwrongpass.text = "Please enter your email"
        self.Emailsign.shake(10,withDelta: 5.0)

     } else {

        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

        func prepare(for segue: UIStoryboardSegue, sender: Any?)
        {
            if segue.destination is SignUpSegue1
            {
                let vc = segue.destination as? SignUpSegue1
                vc?.email = ""

            }
        }


        } else if providers != nil {
            print("L'email inserita è già esistente")
            self.labelwrongpass.text = nil
            self.labelwrongpass.text = "L'email inserita è già esistente"
            self.Emailsign.shake(10,withDelta: 5.0)


            }
    })

     }

     }
       }
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
ozy
  • 21
  • 3
  • I suggest you to define `Dictionary` in `singletonClass` store enter `email` and `password` data in that dictionary. If in future there's requirement to pass more parameter than it helps. You can also use `userDefault` to save `email` and `password` – Kuldeep Apr 13 '18 at 10:47

1 Answers1

0

You can create a var in your destination controller:

class DestinationViewController: UIViewController {

    var variableToShare : String?

    //the rest of the class methods....

And in your controller override PrepareForSegue and something like:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

    // Create a variable that you want to send
    var toShare = "Email"

    // Create a new variable to store the instance of DetinationViewController 
    let destinationVC = segue.destinationViewController as DetinationViewController
    destinationVC.variableToSharer = toShare
    }
}