我有以下带有私有(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
。您需要将 %d
与 Int
一起使用。
关于swift - 在 Swift 中使用 %@ 格式化字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40626006/