Trailing closure passed to parameter of type 'Int' that does not accept a closure

I have TabView in ContentView and I want to add TabView for OnboardingView in OtherView, every things work, but it is throw error for TabView in OtherView like "Trailing closure passed to parameter of type 'Int' that does not accept a closure" I do not know why? Any idea?

ContentView:

struct TabView : View {
   
  var body: some View{
     
    VStack(spacing: 0){
.......
}

OtherView:


   VStack {
    TabView {
      ForEach(onboardingData) { onboardingItem in
         OnboardingCard(onboardingItem: onboardingItem)
      }
  }
  .tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))
  .indexViewStyle(PageIndexViewStyle (backgroundDisplayMode:
  .always))
  .foregroundColor(.white)
}
Answered by skysoft13 in 684092022

As OOPers and Claude mentions in comment, when we called the TabView as MyTabView problem solved

Which line exactly ? Is it line 3 or 4 ? If so, please show how onboardingData and OnboardingCard are defined. Otherwise tell exactly where you get the error.

1.    VStack {
2.     TabView {
3.       ForEach(onboardingData) { onboardingItem in
4.          OnboardingCard(onboardingItem: onboardingItem)
5.       }
6.   }
7.   .tabViewStyle(PageTabViewStyle(indexDisplayMode: .automatic))
8.   .indexViewStyle(PageIndexViewStyle (backgroundDisplayMode: .always))
9.   .foregroundColor(.white)
10. }

on line 2 I get error, in TabView , and  how onboardingData and OnboardingCard are defined it is defined as

OnboardingCard:


fileprivate struct OnboardingCard: View {
  let onboardingItem: OnboardingItem
    var body: some View {
      VStack {
        Image(onboardingItem.imageName)
         .resizable()
        .frame(width:340, height:340)
       
        Text(onboardingItem.title)
        .font(.title)
          .foregroundColor(.black)
        .bold()
        .padding()
        Text(onboardingItem.description)
        .multilineTextAlignment(.center)
        .font(.body)
        .foregroundColor(.gray)
        .padding (.horizontal, 15)
        }
       }
       }

onboardingData:

  var onboardingData: [OnboardingItem] = [
  OnboardingItem(imageName: "image1", title: "Welcome1", description: "description1"),
  OnboardingItem(imageName: "image2", title: "Welcome2", description: "description2"),
    OnboardingItem(imageName: "image3", title: "Welcome3", description: "description3"),
  OnboardingItem(imageName: "image4", title: "Welcome4", description: "description4")
  ]

Doc states :

Tab views only support tab items of type Text, Image, or an image followed by text. Passing any other type of view results in a visible but empty tab item.

like in

TabView {
    Text("The First Tab")
        .badge(10)
        .tabItem {
            Image(systemName: "1.square.fill")
            Text("First")
        }

That's not the case with your code: you return OnboardingCard

ForEach(onboardingData) { onboardingItem in 
    OnboardingCard(onboardingItem: onboardingItem)
}

What is the purpose of VStack for TabView ?

Accepted Answer

As OOPers and Claude mentions in comment, when we called the TabView as MyTabView problem solved

LegalAI /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Services/DocumentService.swift /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Services/DocumentService.swift:92:18 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Utilities/Extensions.swift /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Utilities/Extensions.swift:235:22 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/DocumentViewModel.swift /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/DocumentViewModel.swift:192:8 Invalid redeclaration of 'FormFieldView'

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/ConsultationViewModel.swift /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/ConsultationViewModel.swift:54:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CourseViewModel.swift /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CourseViewModel.swift:29:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CourseViewModel.swift:73:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CourseViewModel.swift:93:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CourseViewModel.swift:122:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CourseViewModel.swift:170:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FranchiseViewModel.swift /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FranchiseViewModel.swift:40:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FranchiseViewModel.swift:69:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FranchiseViewModel.swift:98:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FranchiseViewModel.swift:118:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FranchiseViewModel.swift:133:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FranchiseViewModel.swift:162:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FranchiseViewModel.swift:191:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:34:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:62:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:86:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:110:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:133:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:146:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:159:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:172:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawFirmManagementViewModel.swift:185:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawyerOfficeViewModel.swift /Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/LawyerOfficeViewModel.swift:31:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/TranslationViewModel.swift:53:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FeedbackViewModel.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FeedbackViewModel.swift:26:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/FeedbackViewModel.swift:44:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CalculatorViewModel.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CalculatorViewModel.swift:86:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CalculatorViewModel.swift:267:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/CalculatorViewModel.swift:278:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/VIPViewModel.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/VIPViewModel.swift:29:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/VIPViewModel.swift:49:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/ViewModels/VIPViewModel.swift:83:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Lawyer/AppointmentBookingView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Lawyer/AppointmentBookingView.swift:326:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Lawyer/LawyerDetailView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Lawyer/LawyerDetailView.swift:458:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Lawyer/ReviewSubmissionView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Lawyer/ReviewSubmissionView.swift:295:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/AIConsultation/NewConsultationView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/AIConsultation/NewConsultationView.swift:169:18 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/ForgotPasswordView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/ForgotPasswordView.swift:115:26 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/ForgotPasswordView.swift:195:22 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/LoginView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/LoginView.swift:119:26 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/LoginView.swift:219:22 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/LoginView.swift:257:30 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/RegisterView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/RegisterView.swift:119:26 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Auth/RegisterView.swift:176:18 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Contract/ContractReviewView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Contract/ContractReviewView.swift:184:22 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Contract/ContractUploadSheet.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Contract/ContractUploadSheet.swift:99:22 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Contract/ContractUploadSheet.swift:196:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentCategoriesView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentCategoriesView.swift:25:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentFormView.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentFormView.swift:140:14 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentFormViewEnhanced.swift

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentFormViewEnhanced.swift:106:18 Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentFormViewEnhanced.swift:117:20 Referencing subscript 'subscript(dynamicMember:)' requires wrapper 'ObservedObject<DocumentViewModel>.Wrapper'

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentFormViewEnhanced.swift:117:30 Value of type 'DocumentViewModel' has no dynamic member 'isGenerating' using key path from root type 'DocumentViewModel'

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentFormViewEnhanced.swift:117:30 Cannot convert value of type 'Binding<_>' to expected condition type 'Bool'

/Users/macbook/Documents/develop/2025-12-20/LegalAI_Native/LegalAI_app/Views/Document/DocumentFormViewEnhanced.swift:129:17 Referencing subscript 'subscript(dynamicMember:)' requires wrapper 'ObservedObject<DocumentViewModel>.Wrapper'

on my app i was saw same problme , its errors "Trailing closure passed to parameter of type 'any Decoder' that does not accept a closure" , i was change to swifit language change to verion 6.0 , but same errors , how to fix it

import SwiftUI

struct DocumentTemplatesView: View { @StateObject private var documentService = DocumentService.shared @State private var selectedCategory: DocumentCategory? @State private var selectedTemplate: DocumentTemplate? @State private var searchText = ""

var body: some View {
    NavigationView {
        VStack(spacing: 0) {
            // Search Bar
            HStack {
                Image(systemName: "magnifyingglass")
                    .foregroundColor(.secondary)
                
                TextField("搜索模板", text: $searchText)
                
                if !searchText.isEmpty {
                    Button(action: { searchText = "" }) {
                        Image(systemName: "xmark.circle.fill")
                            .foregroundColor(.secondary)
                    }
                }
            }
            .padding()
            .background(Color(.systemBackground))
            
            // Templates List
            if documentService.isLoading && documentService.categories.isEmpty {
                ProgressView("加载中...")
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
            } else if documentService.categories.isEmpty {
                VStack(spacing: 20) {
                    Image(systemName: "doc.text")
                        .font(.system(size: 60))
                        .foregroundColor(.gray)
                    Text("暂无文书模板")
                        .font(.headline)
                        .foregroundColor(.gray)
                    Button("重新加载") {
                        Task { @MainActor in
                            try? await documentService.fetchCategories()
                        }
                    }
                    .buttonStyle(.bordered)
                }
                .frame(maxWidth: .infinity, maxHeight: .infinity)
            } else {
                ScrollView {
                    LazyVStack(spacing: 16) {
                        ForEach(filteredCategories) { category in
                            CategorySection(category: category, searchText: searchText) { template in
                                selectedTemplate = template
                            }
                        }
                    }
                    .padding()
                }
            }
        }
        .navigationTitle("文书模板")
        .sheet(item: $selectedTemplate) { template in
            if let category = documentService.categories.first(where: { $0.templates.contains(where: { $0.id == template.id }) }) {
                DocumentFormView(template: template, categoryType: category.id)
            }
        }
        .task {
            if documentService.categories.isEmpty {
                _ = try? await documentService.fetchCategories()
            }
        }
    }
}

private var filteredCategories: [DocumentCategory] {
    if searchText.isEmpty {
        return documentService.categories
    }
    
    return documentService.categories.compactMap { category in
        let filteredTemplates = category.templates.filter { template in
            template.name.localizedCaseInsensitiveContains(searchText) ||
            template.desc.localizedCaseInsensitiveContains(searchText)
        }
        
        if filteredTemplates.isEmpty {
            return nil
        }
        
        return DocumentCategory(
            id: category.id,
            name: category.name,
            icon: category.icon,
            description: category.description,
            templates: filteredTemplates
        )
    }
}

}

// MARK: - Category Section struct CategorySection: View { let category: DocumentCategory let searchText: String let onTemplateSelect: (DocumentTemplate) -> Void

var body: some View {
    VStack(alignment: .leading, spacing: 12) {
        // Category Header
        HStack {
            Image(systemName: iconName(for: category.icon))
                .font(.title2)
                .foregroundColor(.blue)
            
            VStack(alignment: .leading, spacing: 4) {
                Text(category.name)
                    .font(.headline)
                Text(category.description)
                    .font(.caption)
                    .foregroundColor(.secondary)
            }
            
            Spacer()
            
            Text("\(category.templates.count)个")
                .font(.caption)
                .foregroundColor(.secondary)
        }
        .padding()
        .background(Color(.systemBackground))
        .cornerRadius(12)
        
        // Templates
        ForEach(category.templates) { template in
            Button(action: { onTemplateSelect(template) }) {
                HStack {
                    VStack(alignment: .leading, spacing: 4) {
                        Text(template.name)
                            .font(.subheadline)
                            .foregroundColor(.primary)
                        Text(template.desc)
                            .font(.caption)
                            .foregroundColor(.secondary)
                            .lineLimit(2)
                    }
                    Spacer()
                    Image(systemName: "chevron.right")
                        .font(.caption)
                        .foregroundColor(.gray)
                }
                .padding()
                .background(Color(.secondarySystemBackground))
                .cornerRadius(8)
            }
        }
    }
}

private func iconName(for icon: String) -> String {
    switch icon {
    case "gavel": return "gavel.fill"
    case "file-signature": return "doc.text.fill"
    case "building": return "building.2.fill"
    case "shield-check": return "checkmark.shield.fill"
    case "balance-scale": return "scale.3d"
    case "heart": return "heart.fill"
    case "globe": return "globe"
    case "lightbulb": return "lightbulb.fill"
    case "briefcase": return "briefcase.fill"
    case "house": return "house.fill"
    default: return "doc.text"
    }
}

}

#Preview { DocumentTemplatesView() }

Trailing closure passed to parameter of type 'Int' that does not accept a closure
 
 
Q