The problem is the following: In my application, you can log in through various social services. network. If the account in social. networks are recorded on different emails, then the input account will be different, and accordingly the token received from the server will be different. When I get a token, I save it to the user defaults, so that later when loading a certain screen I use it. And when I change accounts (but do not exit the application), I always get a new token (the token corresponding to this account) and everything defaults to the user and it works fine. But when I try to load a specific screen, then I have an old token in my dictionary. The dictionary I use to use it in the query. But when I exit the application and re-enter, then the correct token from user defaults is written to my dictionary.

The dictionary looks like this:

var parameters = ["api_token": "\(token!)"] 

Tried and updated like this:

 parameters.updateValue("\(token!)", forKey: "api_token") 

Why it happens? Does not want to change.

Generally a strange topic. Why does my vocabulary generally remain when I exit a function?! Although it is cluss func

  • Although in another place of the code, I have exactly the same moment, but instead of a token, other data is written there and it works fine. Strange topic .... - Dmitriy Greh
  • The answer is found! Thanks to everyone who participated!))) - Dmitriy Greh
  • and what was the problem? - Max Mikheyenko
  • @MaxMikheyenko, there was no error in the dictionary, as it turned out ... I saved the token in a static variable, so that I could use it everywhere, but I could update it only when I started the application again. Just made it so that it was updated again) Children's mistake in fact) - Dmitriy Greh
  • Well, post your answer then - Max Mikheyenko

1 answer 1

Who cares, there was a mistake not in the dictionary, as it turned out ... I saved the token in a static variable, so that I could use it everywhere else, but I could update it only when I started the application again. Just made it so that it is updated again.