0

Context: I have two user types. Depending on which user type you are, the same view controller will appear with different features, controls etc.

How can I store this property about the current user that is always available whenever I am instantiating a view controller to define what they can and can't see/do as the VC loads?

Jabi
  • 101
  • 6
  • set a global variable. – john elemans Feb 03 '21 at 19:22
  • 1
    store the user type in user defaults. Reset it on login and logout. https://developer.apple.com/documentation/foundation/userdefaults https://stackoverflow.com/questions/31203241/how-can-i-use-userdefaults-in-swift https://stackoverflow.com/questions/3074483/save-string-to-the-nsuserdefaults – Sonam Sodani Feb 03 '21 at 19:41

1 Answers1

0

You can get random identifier using uuid:

guard let userIdentifier = UIDevice.current.identifierForVendor?.uuidString else { return }

You can store it with UserDefaults:

let defaults = UserDefaults.standard

defaults.setValue(userIdentifier, forKey: "userID")

And you can get it:

    let userID = defaults.object(forKey: "userID")
Damien
  • 21
  • 2