I have singleton class has lan variable .it is simple like this
class Settings{
// singelton
static let shared = Settings()
var lan:String? = "ar"
private init(){
}
}
and I have a button which change language code for application from ar to en and when I tabbed it again language code changed from en to ar .
@IBAction func languageBtnTabbed(_ sender: Any) {
MOLH.setLanguageTo(MOLHLanguage.currentAppleLanguage() == "en" ? "ar" : "en")
print(MOLHLanguage.currentAppleLanguage())
Settings.shared.lan = MOLHLanguage.currentAppleLanguage()
MOLH.reset()
}
my question is how to update lan variable on setting class with "MOLHLanguage.currentAppleLanguage()"
I tried to update lan variable by using this line : Settings.shared.lan = MOLHLanguage.currentAppleLanguage() but in the fact the lan variable did not change . can any one help me to solve this problem ? and thanks in advance.
i tried to didset{} on lan variable to update it once the language code is changed and the code worked well .
So it might be worth checking what the value of
MOLHLanguage.currentAppleLanguage()is, I suspect that the value ofMOLHLanguage.currentAppleLanguage()is actuallyarperhaps?try changing the default text for
landto something likedefaultand see if value now updates toarwhen you run your code.