Ich habe die folgende Klasse mit privaten Struktur für Strings, die ich sie später für formatierte Zeichenfolgen verwenden möchte. Der Code stürzt jedoch zur Laufzeit ab.Formatieren einer Zeichenfolge mit% @ in Swift
Warum ist das? Liegt es daran, dass es als statisch definiert ist?
Unten ist der gestrippt Code:
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)
}
}
}
Welche Linie verursacht den Absturz? Was ist die Fehlermeldung vom Absturz? – rmaddy
Die Zeile, die mit 'notificationENG =' beginnt, gibt einen Fehler aus. Ich erwähne das im Kommentar am Ende der Zeile. Ich werde es für bessere Sichtbarkeit über die Linie setzen. Der Fehler, den ich bekomme, ist Thread 20: EXC_BAD_ACCESS (Code = 1, Adresse = 0x2) – oyalhi