I want to refactor the API call that is made using async and await but I am getting the error as the publishing needs to be done on the main thread.

The below is the code that I wrote in the file named **LogIn View:**-

```
@State private var quotes = [Quote]()
var body: some View {
    NavigationView {
            List(quotes, id:\.quote_id) { quote in
                VStack(alignment: .leading) {
                    Text(quote.author)
                        .font(.headline)
                    Text(quote.quote)
                        .font(.body)
                }

        }
        .padding()
        .toolbar {
            ToolbarItem(placement: .navigationBarTrailing) {
                Button("Log out") {
                    authentication.updateValidation(success: false)
                }
            }
        }
        .navigationTitle("Dashboard Screen ")
    }

    .task {
        await fetchData()
    }
}

func fetchData() async {
    //create url
    guard let url = URL(string: "https://breakingbadapi.com/api/quotes") else {
        print("URL does not work")
        return
    }

    //fetch data from url
    do {
        let (data, _) = try await URLSession.shared.data(from: url)

        //decode that data

        if let decodeResponse = try? JSONDecoder().decode([Quote].self, from: data) {
            quotes = decodeResponse
        }
    } catch {
        print("Data not valid")
    }
}

```

I want to write the function fetchData() in a separate file and use it here in LogIn View
but upon trying to do so I am getting the error mentioned above. Can anyone Please help me with this.

PS:- all the variables are defined inside another file named **variables**. The code for that is as follows:-

```
import Foundation

struct Quote: Codable {
    var quote_id: Int
    var quote: String
    var author: String
    var series: String
}

```