Despite calling all changes to a Text view within a DispatchQueue.main.async call I still get the purple warning regarding Publishing changes

In my app, I am uploading a file to my server from my ObservableObject (HTTPHandler). The published strings from HTTPHandler are used by the view (UploadTemplate) to convey status and errors.

HTTPHandler, which also handles all my HTTP needs, is obviously thrown off the main queue.

So essentially the view UploadTemplate has Text views which use the string from HTTPHandler.statusMsg to keep the user informed of progress.

I embedded every change of HTTPHandler.statusMsg within a DispatchQueue.main.async yet I still get the warning:

Publishing changes from background threads is not allowed; make sure
to publish values from the main thread (via operators like
receive(on:)) on model updates.

I thought perhaps it’s the initial setting of statusMsg when HTTPHandler is initialized perhaps? All my attempts at figuring this out has led me nowhere with the purple warning.

I’ve double checked that statusMsg is only within HTTPHandler, and that they’re all embedded within a DispatchQueue.main.async call.

Any idea what I might be doing wrong?

import SwiftUI

struct UploadTemplate: View {
    @StateObject var xFile              = XFile()
    @EnvironmentObject var xUser        : XUser
    @State var isShowingDocumentPicker  = false
    @State var error                    = "no error"
    @State var isPerformingURL          = false
    @State var currentStatus            = ""
    @StateObject var httpHandler            = HTTPHandler()
    
    var body: some View {
        NavigationStack {
            ZStack {
                Color.teal
                    .ignoresSafeArea()
                VStack{
                    Text(xFile.fileName.isEmpty ? "No File Selected" : xFile.fileName)

                    Text(httpHandler.statusMsg)

                    Text(httpHandler.errorMsg)

                    
                    Button {
                        isShowingDocumentPicker = true
                    } label: {
                        Text("Select File")
                    }
                    .disabled(isPerformingURL)
                    
                    Button {
                        Task {
                            isPerformingURL = true
                            xFile.fileStage = .uploadOriginal
                            let request = xFile.makePostRequest(xUser: xUser, script: "uploadOrig.pl")
                            var result = await httpHandler.asyncCall(request: request, xFile: xFile)
                        }
                    }
                label: {
                    Text("Upload")
                }
                .disabled((xFile.fullPath.isEmpty || isPerformingURL))
                    
                }
                .navigationTitle("Upload Template")
                .scrollContentBackground(.hidden)
            }
            .fileImporter(
                isPresented: $isShowingDocumentPicker,
                allowedContentTypes: [.spreadsheet, .commaSeparatedText], allowsMultipleSelection: false) { result in
                    switch result {
                    case .success(let file):
                        xFile.fillXFile(fileURL: file[0], xUser: xUser)
                        
                    case .failure(let error):
                        print(error.localizedDescription)
                    }
                }
        }
    }
}







class HTTPHandler: NSObject, ObservableObject {
    @Published var statusMsg    = ""
    @Published var stage = FileStage.makeTicket
    @Published var errorMsg = ""
    
    func asyncCall(request: URLRequest, xFile: XFile) async -> Int {
        
        do {
            let (data, response) = try await URLSession.shared.data(for: request)
            guard let httpResponse = response as? HTTPURLResponse
            else {

                DispatchQueue.main.async { [self] in
                    statusMsg = "Unknown Error 1"
                }

                return 1
            }
            
            if httpResponse.statusCode == 200 {
                if xFile.jsonAndXFile(data: data) {
                    if xFile.hData.status == "SUCCESS" &&
                        xFile.hData.returnvalue == "SSFILEUPLOADED" {
                        xFile.fileStage = .converting
                        DispatchQueue.main.async { [self] in statusMsg = "Converting"}
                    } else if xFile.hData.status == "SUCCESS" &&
                        xFile.hData.returnvalue == "SSCONVERTING" {
                        DispatchQueue.main.async { [self] in statusMsg = String(format: "Converting %@%%", xFile.hData.message)}
                    } else if xFile.hData.status == "SUCCESS" &&
                        xFile.hData.returnvalue == "SSSTAGE1" {
                        DispatchQueue.main.async { [self] in statusMsg = String(format: "Converting %@%%", xFile.hData.message)}
                    }
                    } else {


                    DispatchQueue.main.async { [self] in
                        statusMsg = "JSON err"
                    }


                        return 4
                    }
                } else {
                    DispatchQueue.main.async { [self] in
                    statusMsg = String(format: "URL error: %d", httpResponse.statusCode)}
                    return 3
                }
            } catch {
                DispatchQueue.main.async { [self] in
                statusMsg = "async error: 2"}
                return 2
            }
        return 0
    }
    
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật