Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the string value from Text?

Tags:

swift

swiftui

I have a custom view that gets passed some Text objects. But I can't figure out how to get the string value out of them. For example:

let text = Text("hello")
// no way to get "hello" back

I've gone through the documentation, but for some reason the properties are not publicized.

like image 926
Sam Avatar asked Jul 04 '26 13:07

Sam


1 Answers

I'm not sure of the context and if this helps with your particular scenario, but I came across your post as I had just been having trouble testing a Text value.

What I worked out for me, was I could use the Text's verbatim parameter to test the String (as below):

it("should show the content I'm after") {
  expect(viewModel.someText) == Text(verbatim: "some content I'm after")
}
like image 116
michaelrbg Avatar answered Jul 07 '26 06:07

michaelrbg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!