注册按钮点击功能
Sign up button clicked function
user.signUpInBackground{ (success: Bool, error:Error?) in
if success{
print("signed up")
UserDefaults.standard.set(user.username, forKey: "username")
UserDefaults.standard.synchronize()
user.signUpInBackground {(success: Bool, error: Error?) in
if success {
print("signed up")
AVUser.logInWithUsername(inBackground: user.username!, password: user.password!, block: {(user: AVUser?, error: Error?) in
if let user = user {
UserDefaults.standard.set(user.username, forKey: "username")
UserDefaults.standard.synchronize()
let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
}
})
}else {
print(error!.localizedDescription)
}
}
}
}
我正在编写一个类似于 Instagram 的应用程序。当人们点击登录按钮时,这是代码的一部分。我发现这很难理解。
为什么 UserDefaults.standard
和 if success
在上面的代码中重复?
感谢您的关注。
你试过这样吗..有什么问题吗? :
user.signUpInBackground {(success: Bool, error: Error?) in
if success {
print("signed up")
AVUser.logInWithUsername(inBackground: user.username!, password: user.password!, block: {(user: AVUser?, error: Error?) in
if let user = user {
UserDefaults.standard.set(user.username, forKey: "username")
UserDefaults.standard.synchronize()
let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
}
})
}else {
print(error!.localizedDescription)
}
}
我似乎 user.signUpInBackground
调用了两次方法。所以UserDefaults.standard
成功重复
user.signUpInBackground{ (success: Bool, error:Error?) in
if success{
print("signed up")
UserDefaults.standard.set(user.username, forKey: "username")
UserDefaults.standard.synchronize()
user.signUpInBackground {(success: Bool, error: Error?) in
if success {
print("signed up")
AVUser.logInWithUsername(inBackground: user.username!, password: user.password!, block: {(user: AVUser?, error: Error?) in
if let user = user {
UserDefaults.standard.set(user.username, forKey: "username")
UserDefaults.standard.synchronize()
let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
}
})
}else {
print(error!.localizedDescription)
}
}
}
}
我正在编写一个类似于 Instagram 的应用程序。当人们点击登录按钮时,这是代码的一部分。我发现这很难理解。
为什么 UserDefaults.standard
和 if success
在上面的代码中重复?
感谢您的关注。
你试过这样吗..有什么问题吗? :
user.signUpInBackground {(success: Bool, error: Error?) in
if success {
print("signed up")
AVUser.logInWithUsername(inBackground: user.username!, password: user.password!, block: {(user: AVUser?, error: Error?) in
if let user = user {
UserDefaults.standard.set(user.username, forKey: "username")
UserDefaults.standard.synchronize()
let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.login()
}
})
}else {
print(error!.localizedDescription)
}
}
我似乎 user.signUpInBackground
调用了两次方法。所以UserDefaults.standard
成功重复