NSLocalizedString - 线程1:带String.localizedStringWithFormat的EXEC_BAD_ACCESS

时间:2017-11-14 11:14:43

标签: ios swift string nslocalizedstring

我尝试使用一些本地化变量发出通知。在模拟器中,一切都没有错误 - 即使通知显示应该如此,但如果我在iPhone上测试它,应用程序崩溃。

    func getContent(fromName: String, andDue: String, andAmount: Double) -> UNMutableNotificationContent {
        let currency = self.appDelegate.settings.getShortCurrency() // standard währung aus dem System holen
        let content = UNMutableNotificationContent()


        content.subtitle = NSLocalizedString("REMINDERTITLE", comment: "Reminder: some payments are overdue...")


    // Error in this line:
    content.body = String.localizedStringWithFormat(NSLocalizedString("REMINDERTEXT", comment: "Hey, %@'s payment from %@ %@ is overdue since %@! Do you want to send him a reminder message?"), fromName, andAmount, currency, andDue)

        content.badge = 1
        content.sound = UNNotificationSound(named: "droppingCoin.wav")

        return content
    }

错误是:

  

线程1:EXC_BAD_ACCESS(代码= 1,地址= 0x4084900000000000)

在这一行:

content.body = String.localizedStringWithFormat(NSLocalizedString("REMINDERTEXT", comment: "Hey, %@'s payment from %@ %@ is overdue since %@! Do you want to send him a reminder message?"), fromName, andAmount, currency, andDue)

评论文本是.strings文件中定义的实际本地化文本值。

提前致谢!

1 个答案:

答案 0 :(得分:2)

你正在为andAmount使用错误的格式说明符。 andAmount是double而不是对象,因此请使用%f而不是%@。