List Closure not displaying retrieved data in Simulator UI

I have backend API caller file that retrieves and displays unwrapped JSON data via URLRequest(). All the data is printed to my console when I build the project but it's not being displayed in the actual UI of my iOS simulator.

I have a class in my ContentView that updates the UI and filters the extracted fields shown here below:

    
    class NotionCall: ObservableObject {
        @Published var extractedContent: [BlockBody.Block] = []
        
        func makeAPIRequest() {
            
            makeRequest { results in
                
                let extractedData = results.map { block -> BlockBody.Block in
                    var extractedBlock = block
                    extractedBlock.ExtractedFields = block.paragraph?.textFields.compactMap { textField in
                        textField.PlainText ?? textField.RichText ?? textField.content         //iterate over PlainText, RichText, and Content fields and return the non nill values
                        
                    } ?? []   //validate objects even if they are nil
                    return extractedBlock
                }
                
                
                DispatchQueue.main.async {
                    self.extractedContent = extractedData
                    
                }
            }
        }
    }
    
    
    @StateObject var NotionCaller = NotionCall()   //manage lifecycle of instance
    

And then below here is my SwiftUI structure that contains List(NotionCaller.extractedContent) { block in ForEach(block.ExtractedFields, id: \.self) { field in Text(field) meant to display the extracted data to the UI:

var body: some View {
        NavigationStack {
           
            
            ZStack {
                
                List(NotionCaller.extractedContent) { block in
                    ForEach(block.ExtractedFields, id: \.self) { field in
                        Text(field)
                        
                        
                    }
                    
                }
                
                ZStack {
                    
                    Color(hex: "#f9f9f9")
                        .ignoresSafeArea()
                    
                    
                    VStack {
                        
                        TextField("   Search keywords", text: $searchKeywords)  //change font later
                            .frame(height: 48)
                            .overlay(RoundedRectangle(cornerRadius: 30).strokeBorder(style: StrokeStyle()))
                            .foregroundColor(.white)
                            .background(.white)
                            .cornerRadius(30)
                            .padding()
                            .scaledToFit()
                            .frame(maxHeight: .infinity, alignment: .top)
                        
                    }
                    
                    VStack {
                        
                        Spacer()
                        
                        Divider()
                            .padding()
                        
                        
                        HStack {
                            
                            Button(action: {              //add functionality later
                            }) {
                                
                                Image("menuButton")
                                    .frame(alignment: .bottom)
                                    .padding(.horizontal, 42)
                                Spacer()
                                
                            }
                            
                            HStack {
                                Button(action: {              //add functionality later
                                }) {
                                    
                                    Image("notificationButton")
                                        .frame(alignment: .leading)
                                        .padding(.leading, 30)
                                    Spacer()
                                }
                            }
                            
                            HStack {
                                Button(action: {
                                }) {
                                    Image("notionImportButton")
                                        .frame( alignment: .trailing)
                                        .padding(.horizontal)
                                        .padding(.horizontal)
                                }
                            }
                        }
                        
                        .onAppear {
                            NotionCaller.makeAPIRequest()
                        }
                        
                    }
                    
                    
                    
                }
            }
        }
    }
}

We cannot test with the code you posted. So only some guesses.

Why do you need to

DispatchQueue.main.async

And try to connect

.onAppear {
    NotionCaller.makeAPIRequest()
}

to the ZStack or the List and not the VStack

@Claude31 so My .onAppear should be called in the same place as my List()? since it’s in my ZStack?

You should receive a runtime warning about updating your data when you do this:

DispatchQueue.main.async {
    self.extractedContent = extractedData
}

Try with this instead

Task { @MainActor in
    self.extractedContent = extractedData
}

Here is what I propose to test for onAppear

    var body: some View {
        NavigationStack {
            
            ZStack {
                List(NotionCaller.extractedContent) { block in
                    ForEach(block.ExtractedFields, id: \.self) { field in
                        Text(field)
                    }
                }
                .onAppear {         // <<-- EITHER HERE
                        NotionCaller.makeAPIRequest()
                 }
                
                ZStack {
                    Color(hex: "#f9f9f9")
                        .ignoresSafeArea()
                    
                    VStack {
                        TextField("   Search keywords", text: $searchKeywords)  //change font later
                            .frame(height: 48)
                            .overlay(RoundedRectangle(cornerRadius: 30).strokeBorder(style: StrokeStyle()))
                            .foregroundColor(.white)
                            .background(.white)
                            .cornerRadius(30)
                            .padding()
                            .scaledToFit()
                            .frame(maxHeight: .infinity, alignment: .top)
                    }
                    
                    VStack {
                        Spacer()
                        Divider()
                            .padding()
                        
                        HStack {
                            Button(action: {              //add functionality later
                            }) {
                                Image("menuButton")
                                    .frame(alignment: .bottom)
                                    .padding(.horizontal, 42)
                                Spacer()
                            }
                            
                            HStack {
                                Button(action: {              //add functionality later
                                }) {
                                    
                                    Image("notificationButton")
                                        .frame(alignment: .leading)
                                        .padding(.leading, 30)
                                    Spacer()
                                }
                            }
                            
                            HStack {
                                Button(action: {
                                }) {
                                    Image("notionImportButton")
                                        .frame( alignment: .trailing)
                                        .padding(.horizontal)
                                        .padding(.horizontal)
                                }
                            }
                        }
                        
                        // .onAppear {          // <<-- NOT HERE
                        //     NotionCaller.makeAPIRequest()
                        // }
                        
                    }
                    
                }
            }
            .onAppear {         // <<-- OR HERE
                NotionCaller.makeAPIRequest()
            }
        }
    }
}
List Closure not displaying retrieved data in Simulator UI
 
 
Q