Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SwiftUI problem on visualization of int inside a text

I’m using Xcode 14 and I have a text that has o show a int value that represent the current year so in my view-model I found the year in that way

@Published var selectedYear: Int = Calendar.current.component(.year, from: Date())

and after I put the variable in the text

Text("\(vm.selectedYear)")

but in the view it is shown like this : 2,022 instead of 2022 and I don’t understand why

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

it seams only a problem on representation in text because if printed it show 2022

thanks

>Solution :

try this, works for me:

Text(String(vm.selectedYear))

See also this post: String interpolation in Swift for how to use custom interpolations

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading