What to remove on logout

Persistence Senior Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Pick the fix

Which logout plan is complete?

Options
Hint 1 of 1

Think storage, network, system and memory.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Revoke tokens on the server; clear Keychain, database, caches, cookies, web data, user defaults and App Group data; unregister push; cancel tasks; reset in-memory state

Correct. It covers storage, network, system integrations and memory.

Why not the others?
  • B Delete the access token from the Keychain. Cached data, web cookies and pushes still belong to the old user.
  • C Delete the app's Documents folder. It misses the Keychain, cookies, push and server tokens.
  • D Show the login screen and keep the data for faster re-login. On a shared device, the next user sees the previous user's data.

30-second answer

Everything tied to that account: Keychain tokens and credentials, the user's database rows, caches and files, URLCache, cookies and WKWebView website data, user-scoped UserDefaults keys and App Group data used by widgets. Also unregister the push token on the server, cancel background tasks and uploads, clear in-memory state, and remove Spotlight items and notifications.

Practise saying it · 60 s. No recording, just a timer

Explain what logout must clear.

Say your answer out loud, then check which of these points you covered:

  • Credentials
  • Local data and caches
  • Web and push
  • Memory and tasks

Deep dive

Keep one place that knows every user-scoped store, so new features register there.

Keychain items can survive app deletion, so clean them on first launch after reinstall too.

Reset widgets with WidgetCenter.reloadAllTimelines() after clearing shared data.

Tell the server so it revokes refresh tokens.

Common mistakes

  • Deleting only the token.
  • Forgetting web view cookies and widget data.

Senior take & follow-ups

Seniors give a complete inventory and design for it, not a one-off list.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why clean the Keychain on first launch?

    Show hint

    Items can survive deleting the app.

  2. How do you avoid missing stores?

    Show hint

    A registry of user-scoped storage that logout iterates.

Suggest a fix if something here is wrong or out of date.