swift - 在 Swift 中使用 %@ 格式化字符串

我有以下带有私有(private)结构的字符串类,我想稍后将它们用于格式化字符串。但是,代码在运行时崩溃。

这是为什么?是不是因为它被定义为static let?

以下是剥离的代码:

class LGNotificationHandler {
    private struct Strings {
        static let SentImagesENG = "Sent %@ images to the event"
        static let SentImagesTUR = "Etkinliğe %@ görsel gönderdi"
    }

    func buildNotificationString(imageCount: Int) -> String {
        if imageCount == 1 {
        .
        .
        .

        } else {
            // below line is giving error at run time
            notificationENG = String(format: Strings.SentImagesENG, imageCount)  
            notificationTUR = String(format: Strings.SentImagesTUR, imageCount)  
        }
    }
}

最佳答案

您忽略了提供有关崩溃的任何详细信息,但一个明显的问题是使用 %@ 格式说明符和 Int。您需要将 %dInt 一起使用。

https://stackoverflow.com/questions/40626006/

相关文章:

html - 在电子邮件正文中应用 HTML 格式

java - 将 double 格式设置为分数

java - 更改java控制台输出的颜色

time - ColdFusion - 从分钟数创建时间

reporting-services - SSRS 格式显示为百分比

c# - 在 DataGridView 列中格式化 TimeSpan

c# - 从时间中删除前导零以显示耗时

c++ - Qt - QPushButton 文本格式

sql-server - SQL 2008 使用 LTrim(RTrim 并且数据中仍有空格

haskell - 如何将 Rational 转换为 "pretty"字符串?