无法将类型“()”的值转换为预期的参数类型“(() -> Void)?”在 swiftui 中

Cannot convert value of type '()' to expected argument type '(() -> Void)?' in swiftui

我收到错误无法将类型“()”的值转换为预期的参数类型“(() -> Void)?”在使用 perform action onAppear 函数时。下面是代码。

这是将显示 images/Video/PDF 个文件的视图

struct AssetView: View {
    @ObservedObject var messageAttachmentViewModel: MessageAttachmentViewModel
    var index: Int
    var body: some View {
        let messageAttachmentModel = messageAttachmentViewModel.commonMessageAttachmentModel[index]
        switch messageAttachmentModel.uploadStatus {
        case .idle:
            Color.clear.onAppear(perform: messageAttachmentViewModel.uploadFileData(index: index)) // ERROR
        case .failed(let error):
            ProgressView()
        case .loading(let progress):
         //   print(progress)
            ProgressView(value: progress.fractionCompleted, total: Double(progress.totalUnitCount))
        case .loaded:
            ZStack(alignment: .trailing) {
                if messageAttachmentModel.assetType == .Photo {
                    PhotoView(messageAttachment: messageAttachmentModel)
                } else if messageAttachmentModel.assetType == .Video {
                    VideoView(messageAttachment: messageAttachmentModel)
                } else if messageAttachmentModel.assetType == .PDF {
                    PDFView(messageAttachment: messageAttachmentModel)
                }
            }
            .background(Color.red)
            .frame(width: 150, height: 150)
        }
    }
}

将其放入显式闭包中,如

case .idle:
    Color.clear.onAppear {
       messageAttachmentViewModel.uploadFileData(index: index)
    }

它报告了错误,因为尝试将 messageAttachmentViewModel.uploadFileData() 的返回值 Void 转换为预期的无参数闭包。