[英]How do I connect my login screen to a specific website & database to accept usernames and passwords?
[英]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"))
}
你的代码有很多问题。 试试看,让我知道它是否有效。 我还为我所做的更改添加了解释。
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")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.