swiftswift5nslocalizedstring

Keep getting null using NSLocalizedString in Swift


So this is my code.

let arrowUp = "\u{2191}" 
let percentageDif = (pctDiff(x1: yesterdayValue, x2: todaysValue)) // Exp.  -27.79 

       let showDiffrence = String.localizedStringWithFormat(NSLocalizedString("%@ Day %@", comment: "Show Diffrence"), arrowUp, percentageDif)

While I have "arrowUp" constant showing up, Im keet getting (null) for the second one. I tried using "%d" but I get zero. The word "Day" gets translated correctly from my Localizable.strings.


Solution

  • Modify your declaration to this:

    let showDiffrence = "\(arrowUp) \(NSLocalizedString("Day", comment: "Show Diffrence")) \(percentageDif)"