I defined iTunes categories in my code like this:
public enum ItunesCategoryType: Int {
case arts = 1
case business = 8
case comedy = 14
case education = 15
case gamesHobbies = 21
case governmentOrganizations = 27
case health = 32
case kidsFamily = 37
case music = 38
case newsPolitics = 39
case religionSpirituality = 40
case scienceMedicine = 48
case societyCulture = 52
case sportsRecreation = 57
case technology = 62
case tvFilm = 67
}
public struct ItunesCategory {
public var id: Int {
return type.rawValue
}
public let type: ItunesCategoryType
public var name: String {
switch type {
case .arts: return NSLocalizedString("arts", value: "Arts", comment: "")
case .business: return NSLocalizedString("business", value: "Business", comment: "")
case .comedy: return NSLocalizedString("comedy", value: "Comedy", comment: "")
case .education: return NSLocalizedString("education", value: "Education", comment: "")
case .gamesHobbies: return NSLocalizedString("games-hobbies", value: "Games & Hobbies", comment: "")
case .governmentOrganizations: return NSLocalizedString("government-organizations", value: "Government & Organizations", comment: "")
case .health: return NSLocalizedString("health", value: "Health", comment: "")
case .kidsFamily: return NSLocalizedString("kids-family", value: "Kids & Family", comment: "")
case .music: return NSLocalizedString("music", value: "Music", comment: "")
case .newsPolitics: return NSLocalizedString("news-politics", value: "News & Politics", comment: "")
case .religionSpirituality: return NSLocalizedString("religion-spirituality", value: "Religion & Spirituality", comment: "")
case .scienceMedicine: return NSLocalizedString("science-medicine", value: "Science & Medicine", comment: "")
case .societyCulture: return NSLocalizedString("society-culture", value: "Society & Culture", comment: "")
case .sportsRecreation: return NSLocalizedString("sports-recreation", value: "Sports & Recreation", comment: "")
case .technology: return NSLocalizedString("techology", value: "Technology", comment: "")
case .tvFilm: return NSLocalizedString("tv-film", value: "TV & Film", comment: "")
}
}
public init(type: ItunesCategoryType) {
self.type = type
}
}
As you can see I want the category names to be localized.
Localizable.strings contains (among others)
"arts" = "Kunst";
Somewhere in my code I run this:
print(ItunesCategory(type: .arts).name)
I run my app with Application Language and Region set to German. This does not print the translated value. It prints Arts instead of Kunst.
Why does it not print the correctly localized String? I assume this is due to compiler optimizations?