Kevin Renskers
Kevin Renskers

Reputation: 5892

SwiftUI default formatter in Text views?

I was surprised to find that some kind of default number formatter is applied to SwiftUI Text? For example, with this code:

.navigationBarTitle("\(viewingYear)", displayMode: .inline)

Where viewingYear is the integer 1491, it is shown like this:

enter image description here

How do I disable this behavior so it's shown as 1491 and not 1,491?

Upvotes: 3

Views: 308

Answers (2)

Kevin Renskers
Kevin Renskers

Reputation: 5892

It seems the most SwiftUI-y way is this:

Text(verbatim: "\(viewingYear)")

Upvotes: 0

Asperi
Asperi

Reputation: 257493

Use it as string literal like below

.navigationBarTitle(LocalizedStringKey(stringLiteral: "\(viewingYear)"), 
     displayMode: .inline)

Upvotes: 2

Related Questions