I have created login page. when I enter email and password returns from Json the user ID and then, I have saved the ID in user default to be able to use it in different pages in my app, but when I added logout button in another page. the function of the logout button is when I press it delete id from user default and then take me to the root uiviewcontroller but when I logout and login with another account steal saving the old ID.
//save id to the user default by using login button
let id = UserDefaults.standard
id.set(data.id , forKey : "ID")
id.synchronize
//using user id with this code in diferent pages
let user_id = UserDefaults.standard.integer(forKey : "ID")
//delete id from user default by using logout button
UserDefaults.standard.removeObject(forKey : "ID")
userDefaults.synchronize
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let mainScreen = UIStoryboard.init(name : "Main" , bundle : nil).instantiateViewController(withIdentifier :"BG")
appDelegate.window?.rootViewController = mainScreen