Is it possible to override a global function in Swift?
Specifically, I want to override NSLocalizedString
. This was easy in Objective-c (#undef
/ #define
), but in Swift NSLocalizedString
is defined as a global function, and I cannot find a way to override it.
I could make my own function MyLocalizedString
, which called the original NSLocalizedString
, but then I would lose the clever support that AppCode has for Localizable.strings files (autocompletion of localization-keys, IDE showing the localized text) and I would have to ensure that every use of NSLocalizedString
in my code is replaced with MyLocalizedString
.
Edit: What do I want to achieve? I want to be able to dynamically change the strings in the GUI. The easiest is to redefine NSLocalizedString and then look up the string in a table myself. If it is not there, I will use the original string from Localizable.strings.