I have text coming from an API call. I want to display it. The issue is as below:
Dummy data provided to run
struct SampleTypeBox: View {
var sampleType : [SampleTypeList]
VStack(alignment: .leading,spacing: 20){
HStack{
ForEach(sampleType.indices,id:\.self){sample in
Text("\(sample+1)." + "\(sampleType[sample].SampleName)")
.font(.system(size: 13))
.foregroundColor(.green)
}
}
struct SampleTypeBox_Previews: PreviewProvider {
static var previews: some View {
let SampleList =
[
SampleTypeList(
TestSampleTypeId: "50",
SampleName: "2 ml Serum",
ColourCode: "#FFB500"
),
SampleTypeList(
TestSampleTypeId: "55",
SampleName: "EDTA Whole Blood",
ColourCode: "#FFB500"
),
SampleTypeList(
TestSampleTypeId: "55",
SampleName: "EDTA Whole Blood",
ColourCode: "#FFB500"),
SampleTypeList(
TestSampleTypeId: "55",
SampleName: "EDTA Whole Blood",
ColourCode: "#FFB500"),
SampleTypeList(
TestSampleTypeId: "55",
SampleName: "EDTA Whole Blood",
ColourCode: "#FFB500")
]
SampleTypeBox(sampleType: SampleList)
}
}
I have attached pic. The green shows what I am getting and the red color output is what I want.
Textto display everything, not anHStack. Collect all the data into oneStringand put that in aText. Is that what you want?