我有下面的类,它包含字符串的私有结构,我想稍后将它们用于格式化的字符串。但是,代码在运行时崩溃。在Swift中用%@格式化字符串
这是为什么?是因为它被定义为静态的让?
下面是剥离代码:
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)
}
}
}
哪条线路导致崩溃?什么是从崩溃错误信息? – rmaddy
以'notificationENG ='开头的行会给出错误。我在最后的评论中提到了这一点。为了更好的可视性,我会把它放在线上。我得到的错误是线程20:EXC_BAD_ACCESS(code = 1,address = 0x2) – oyalhi