登录后如何将登录屏幕与主屏幕连接起来?

How do I connect my login screen with my home screen after I login?

我有一个登录屏幕,我想在登录后将它与我的主页连接起来。我创建了一个带有标识符的 Segue,但是当我尝试时它不起作用。我能做什么?

let message = json!["message"] as? String

if (message?.contains("success"))!
{                                                   
    self.performSegue(withIdentifier: "homelogin", sender: self)

    let id = json!["id"] as? String
    let name = json!["name"] as? String
    let username = json!["username"] as? String
    let email = json!["email"] as? String


    print(String("Emri") + name! )
    print(String("Emaili") + email! )
    print(String("Id") + id! )
    print(String("username") + username! )                                                      
}
else
{
    print(String("check your password or email"))
}

this is the segue with Identifier

您的代码有很多问题。尝试一下,让我知道它是否有效。我还添加了对所做更改的解释。

if let json = json { // The “if let” allows us to unwrap optional values safely only when there is a value, and if not, the code block will not run and jump to else statement

    let message = json["message"] as? String ?? "" // The nil-coalescing operator (a ?? b) unwraps an optional a if it contains a value, or returns a default value b if a is nil. 

    if message == "success" {
        DispatchQueue.main.async {
            self.performSegue(withIdentifier: "homelogin", sender: self)
        }

        let id = json["id"] as? String ?? "" // String can directly be entered in double quotes. no need to use String()

        let name = json["name"] as? String ?? ""
        let username = json["username"] as? String ?? ""
        let email = json["email"] as? String ?? ""



        print("Emri " + name )
        print("Emaili " + email )
        print("Id " + id )
        print("username " + username )


    }else{
        print("check your password or email")
    }
} else {
    print("Invalid json")
}