【问题标题】:Swift 3 (Xcode 8 beta 6) localizedStringWithFormatSwift 3(Xcode 8 beta 6)localizedStringWithFormat
【发布时间】:2016-08-22 13:49:10
【问题描述】:

有没有更好的方法来获取本地化格式并使用 Xcode 8 Swift 3 替换字符串?是否需要使用 NSString,并在 NSString 和 String 之间来回转换?

let localizedDue = NSString.localizedStringWithFormat(NSLocalizedString("Due: %@", comment: "due date label with date") as NSString, formattedDate) as String

【问题讨论】:

    标签: ios localization swift3 xcode8-beta6


    【解决方案1】:

    我可能遗漏了一些东西,但在 Swift 3 中,String 有一个类型方法 localizedStringWithFormat,你可以这样写:

    let localizedDue = String.localizedStringWithFormat(NSLocalizedString("Due: %@", comment: "due date label with date"), formattedDate)
    

    如果这不是您想要的,请更新您的帖子。

    【讨论】:

    • 谢谢。我以为我已经尝试过了。也许 Xcode 中的代码完成工具没有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 2016-11-21
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 2014-10-29
    相关资源
    最近更新 更多