I have a weird inconsistency with my localizable
strings
where sometimes the value
is shown and sometimes thee key
is shown. It's about every other time I restart the app. I use a lot of localizable
strings
in the project and they all work fine except for the ones I use in conjunction with this enum
, which of course makes me think there is something wrong with it:
enum ParameterDescription {
case parameterDescription(id: Int)
var description: String {
switch self {
case .parameterDescription(let id):
return "parameterDescription_\(id)"
}
}
}
This returns the string
I expect, like parameterDescription_0
or parameterDescription_3
. And then I hook on localized
:
print(ParameterDescription.parameterDescription(id: 0).description.localized())
extension String {
func localized() -> String {
return NSLocalizedString(self, comment: "")
}
}
And sometimes I get the correct associated value, but if I build and run the code again without changing anything, I (might) get the key
printed as a string
instead, which I guess means that Xcode
couldn't find the string
.
Is there something wrong with the enum
or some reason it can't be used like this? Or is it something else? I have checked through the project folders so that there aren't any conflicting files, and as I previously said, I only experience this problem using this enum
and/or this key
. And there are thousands of localized
strings
in the project.
I have checked similar threads, but there doesn't seem to be any answer that is relevant for this.