2016-12-27 10 views
0

1..2のような範囲を含む文字列をローカライズしようとしています。私はString.localizedStringWithFormatを使用しています:String.localizedStringWithFormatが間違った結果を返します

func testLocalizableString() -> String { 
    let lowerBound = 1 
    let upperBound = 2 
    return String.localizedStringWithFormat(
     NSLocalizedString("Unit.Meters.Range", value:"%d-%dm", comment: ""), 
     [lowerBound, upperBound] 
    ) 
} 

しかし、私は奇妙な結果を得る: "103,413,600-0mを"。

1つの引数(「%dm」のみで、「%d-%dm」ではなく)を使用して1つの数値だけを渡すと、すべて問題ありません。

私のコードに間違いがあり、CVarArg引数でローカライズ可能な文字列を適切にフォーマットする方法はありますか?

func testLocalizableString() -> String { 
    let lowerBound = 1 
    let upperBound = 2 
    return String.localizedStringWithFormat(
     NSLocalizedString("Unit.Meters.Range", value:"%ld-%ldm", comment: ""), 
     lowerBound, upperBound 
    ) 
} 

答えて

0

String.localizedStringWithFormat(_ format: String, _ arguments: CVarArg...) 

の2番目のパラメータを使用すると、指定されたタイプではない配列をゼロ以上 引数を渡す必要があることを意味可変長パラメータ、でありますまた、Intの書式指定子は%ldであり、%dではありません。

関連する問題