Post

Replies

Boosts

Views

Activity

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.
// Füge OrderRow hinzu struct OrderRow: View { let order: Order var body: some View { VStack(alignment: .leading, spacing: 8) { HStack { Text("Tisch \(order.tableNumber)") .font(.headline) Spacer() Text(order.status.rawValue) .font(.caption) .padding(.horizontal, 8) .padding(.vertical, 4) .background(order.status.color.opacity(0.2)) .foregroundColor(order.status.color) .cornerRadius(8) } Text(order.timestamp, style: .time) .font(.caption) .foregroundColor(.gray) ForEach(order.items) { item in Text("\(item.quantity)x \(item.item.name)") .font(.subheadline) } HStack { Spacer() Text(String(format: "%.2f €", order.totalAmount)) .bold() } } .padding() .background(Color.white) .cornerRadius(12) .shadow(radius: 2) } } struct MenuItemRow: View { let item: MenuItem var body: some View { HStack { Text(item.name) .font(.headline) Spacer() Text(String(format: "%.2f €", item.price)) .font(.subheadline) } .padding() } } 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() }
4
0
343
Nov ’24