-->

Variables across all view controllers [closed]

2019-10-07 22:31发布

问题:

In my Login screen, after the login has been accepted, a number is given to that particular user as UserNum so i can access information stored in arrays.

My question is: how can i use this variable across all of my viewControllers to display the information that i get from using my array?

回答1:

One way to do this is creating a new Swift Files, and make a struct with static variables like this:

struct CommonValues {
    static var UserNum: Int = 0
}

And then, you modify it in any view controller if you need it.

You maybe should save it and load it as well, I recommend UserDefaults for that.