Как мне связать мой экран входа в систему с моим главным экраном после входа в систему? - PullRequest
0 голосов
/ 27 мая 2020

У меня есть экран входа в систему, и я хотел связать его с моей домашней страницей после входа в систему. Я создал переход с идентификатором, но он не работает, когда я пробую его. Что я могу сделать?

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"))
}

это переход с идентификатором

1 Ответ

2 голосов
/ 27 мая 2020

Есть много проблем с вашим кодом. Попробуйте и дайте мне знать, работает ли оно. Я также добавил объяснение сделанных мною изменений.

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")
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...