-5

I'm looking for format a text to automatically capitalise the first letter of every word

 Text("hello world")

Will show as:

Hello World
Theoutsider
  • 63
  • 1
  • 7
  • Does this answer your question? [Swift apply .uppercaseString to only the first letter of a string](https://stackoverflow.com/questions/26306326/swift-apply-uppercasestring-to-only-the-first-letter-of-a-string) – Joakim Danielson May 06 '21 at 20:23
  • not really. I'm looking for a solution on swiftui – Theoutsider May 06 '21 at 20:31
  • Not sure what the difference is since it’s a string you are dealing with. I noticed I used the wrong link, this is the one I meant, https://stackoverflow.com/questions/29261218/how-to-capitalize-each-word-in-a-string-using-swift-ios – Joakim Danielson May 06 '21 at 20:35

1 Answers1

4

Any Swift (NS)String API can be used also in SwiftUI

Text("hello world".capitalized)
vadian
  • 274,689
  • 30
  • 353
  • 361
  • It does, because it’s only available because of the SwifUI import; it’s misleading to call it String API. –  May 06 '21 at 20:31
  • Keep in mind that a `Text` with a `String` capitalized like this won't be automatically localized – zh. Jul 11 '22 at 15:05