Ios 由于编译器优化,无法本地化字符串?

Ios 由于编译器优化,无法本地化字符串?,ios,swift,nslocalizedstring,Ios,Swift,Nslocalizedstring,我在代码中定义了iTunes类别,如下所示: 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 kidsFamil

我在代码中定义了iTunes类别,如下所示:

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
    }
}
如您所见,我希望将类别名称本地化

可本地化。字符串
包含(以及其他内容)

在我的代码中,我运行以下命令:

print(ItunesCategory(type: .arts).name)
我运行应用程序时,应用程序语言和区域设置为德语。这不会打印转换后的值。它打印的是
Arts
,而不是
Kunst


为什么不打印正确本地化的字符串?我认为这是由于编译器优化造成的?

这不是编译器问题。本地化被放置在一个框架内。我没有为NSLocalizedString定义捆绑包。因此,无法找到本地化字符串


您是否尝试过NSLocalizedString(“艺术”,注释:),而不是NSLocalizedString(“艺术”,值:“艺术”,注释:)?是的,我尝试过。在这种情况下,它会打印
arts
。这应该是可行的。您可能会被遗漏在问题之外。编译器优化与此无关。您的
可本地化.strings
文件是否放置正确?有其他本地化语言吗?如果是,它们是否有效?您正在运行ond设备还是模拟器?“你试过清理和重建你的项目,重新安装吗?”那个懒汉说웃 你说得对。我错过了一些我不知道的事情。本地化被放置在一个框架内。我没有为NSLocalizedString定义捆绑包。因此,无法找到本地化字符串。这帮助了我:
print(ItunesCategory(type: .arts).name)