I create a struct to store Strings for the project.
Example:
struct StringStruct {
     var BUTTON_TITLE: String = "Okay"
     var CANCEL_TITLE: String = "I don't think so"
     var DECLINE_TITLE: String = "No"
     var PROFILE_TABBAR_TITLE: String = "My Profile"
}
In the app, I could change these variables at some point.
I am wondering if I could reset all value back to the initial state?
The easiest way to reset a StringStruct variable would be to
assign a new default value:
var strings = StringStruct()
strings.DECLINE_TITLE = "Nein"
strings = StringStruct()
If you want to do that as a (mutating) function then I would implement it as
struct StringStruct {
    var BUTTON_TITLE: String = "Okay"
    var CANCEL_TITLE: String = "I don't think so"
    var DECLINE_TITLE: String = "No"
    var PROFILE_TABBAR_TITLE: String = "My Profile"
    mutating func reset() {
        self = StringStruct()
    }
}
which eliminates the need to repeat all default values.
struct StringStruct {
     var BUTTON_TITLE: String = "Okay"
     var CANCEL_TITLE: String = "I don't think so"
     var DECLINE_TITLE: String = "No"
     var PROFILE_TABBAR_TITLE: String = "My Profile"
     mutating func reset() {
         BUTTON_TITLE = "Okay"
         CANCEL_TITLE = "I don't think so"
         DECLINE_TITLE = "No"
         PROFILE_TABBAR_TITLE = "My Profile"
     }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With