Post

Replies

Boosts

Views

Activity

Reply to I get this Issue : ContentView.swift:3016:25 The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions. But I don´t know what I have to do. I am a noob. Can anybody help me.
Can you give me the right code to solve this issue please struct MenuItemsView: View { @Binding var selectedItems: [OrderItem] @Environment(\.dismiss) private var dismiss func filteredItems(for category: MenuCategory) -> [MenuItem] { return sampleMenuItems.filter { $0.category == category } } func addItemToOrder(_ item: MenuItem) { if let index = selectedItems.firstIndex(where: { $0.item.id == item.id }) { selectedItems[index].quantity += 1 } else { selectedItems.append(OrderItem(item: item, quantity: 1)) } } var body: some View { NavigationView { List { ForEach(MenuCategory) { category in Section(header: Text(category.rawValue)) { let filteredItems = sampleMenuItems.filter ForEach(filteredItems) { item in } MenuItemRow(item: sampleMenuItems.filter) { addItemToOrder } } } } } .navigationTitle("Menü") .toolbar { ToolbarItem(placement: .navigationBarTrailing) { Button("Fertig") { dismiss() } } } } } } // Sample Menü-Items let sampleMenuItems: [MenuItem] = [ MenuItem(name: "Cola", description: "0,33l", price: 3.50, category: .drinks, image: "cola"), MenuItem(name: "Sprite", description: "0,33l", price: 3.50, category: .drinks, image: "sprite"), MenuItem(name: "Bier", description: "0,5l", price: 4.00, category: .drinks, image: "beer"), MenuItem(name: "Nachos", description: "mit Käsesauce", price: 5.50, category: .snacks, image: "nachos"), MenuItem(name: "Pommes", description: "mit Ketchup", price: 4.50, category: .food, image: "fries"), MenuItem(name: "********", description: "alkoholfrei", price: 6.50, category: .specials, image: "********") ] struct NewEventView: View { var body: some View { Text("New Event") } } struct EventManagementView: View { var body: some View { Text("Event Management") } } struct OrderRow: View { var order: String var body: some View { Text("Order: \(order)") } } #Preview { ContentView() }
Nov ’24