Learn Courses My Dashboard

I'm wondering if there is a way to use the observed object property with the storyboard. I am storing the users email in a structure so that it can be called later to designate the document path that I want to call information from in Firebase

Here is my error - Exception NSException * “Document path cannot be empty.” 0x0000600003eacf00

//Here is my info structure
///

class Info: ObservableObject{

var id: String = “”

var group: String = “”

var email: String = “”

}

///
Here is my part of my login view controller where I pass email into info structure
else{
// create cleaned version of text fields
let Email = EmailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let Password = PasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
//signing in user
Auth.auth().signIn(withEmail: Email, password: Password) { [self] Result, Error in

            if Error != nil{
            //Couldn't sign in
                self.ErrorLabel.text = Error!.localizedDescription
                self.ErrorLabel.alpha = 1
            }
            else{
                let db = Firestore.firestore()
                db.collection("users").document(Email).getDocument{ snappy, Error in
                    if Error == nil{
                           if let snappy = snappy {
                                Info().group = "geny"
                                Info().id = snappy.documentID
                                Info().email = Email
                                let HomeViewController = self.storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.HomeViewController) as? HomeViewController
                                   
                                    self.view.window?.rootViewController = HomeViewController                                   }

                                   }

///Here is my create group view controller where I try to use the email that I passed into my Info structure to designate the correct document path.

@Published var d = Info()

override func viewDidLoad() {
    super.viewDidLoad()
    Utilities.styleTextField(GroupName)
    Utilities.styleFilledButton(CreateGroup)
    
}

@IBAction func CreateGroup(_ sender: Any) {
    if GroupName.text!.trimmingCharacters(in: .whitespacesAndNewlines) == "" {
        ErrorLabel.text = "Please specify group name"
        ErrorLabel.alpha = 1
    }
    else{
        let i = GroupName.text!.trimmingCharacters(in: .whitespacesAndNewlines)
        let db = Firestore.firestore().collection("users")
        let x = d.email
        ErrorLabel.text = x
        ErrorLabel.alpha = 1
        db.document(x).setData(["Group" : i], mergeFields: ["Group"]) { Error in
            if Error == nil{
                let HomeViewController = self.storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.HomeViewController) as? HomeViewController
            
                self.view.window?.rootViewController = HomeViewController
                self.view.window?.makeKeyAndVisible()
                
            }
            else{
                self.ErrorLabel.text = "Error"
                self.ErrorLabel.alpha = 1}
        }
    }

Sorry if I didn’t format this question in a very clear way. I know I’m not using he observable object and published properties correctly, I just got desperate and started trying different things. I saw how to use them correctly when making your view through code but am not sure how to use them when using storyboard. Please help.