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)
}
}
}
}
I am writing an app just like Instagram. This is a part of code when people click sign in button. I found it is quite difficult to understand.
Why UserDefaults.standard
and if success
repeat in the above code ?
Thanks for your attention.