我有一个包含私有结构体字符串的类,我希望以后可以将它们用于格式化字符串。然而,在运行时代码崩溃了。
为什么会这样?是因为它被定义为静态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)
}
}
}