N
N
Nikita Bratsky2019-02-05 21:53:00
Swift
Nikita Bratsky, 2019-02-05 21:53:00

Need a variable to get its value in different classes, how to be?

You need to save the username and get its value in different classes, I thought to use UserDefaults, but the key will not be known, what then?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nikita Bratsky, 2019-02-06
@NikBr_9

The answer is here:
https://medium.com/@nimjea/userdefaults-in-swift-4...

B
briahas, 2019-02-15
@briahas

The best thing is to get used to writing correctly.
And it is correct that such a thing as you described never happened.
If you need a variable to be used in different classes - pass it to instances of these classes. Using UserDefaults to pass a variable (???!!!!!!) is the wildest slag.

U
uzolenta, 2019-04-08
@uzolenta

import Foundation
import UIKit

final class shared{
    static var users: String = ""
}

assignment: shared.users = "VALUE"
access the variable just like shared.users

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question