// 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() }
You have a few lines where you do something like sampleMenuItems.filter
but you haven't told it what to filter for.
You need to do something like this: let filteredItems = sampleMenuItems.filter { $0.cost > 100 }
And, as the error is telling you, you need to split your code into smaller chunks to see where the error is. Just comment out a section at a time and see whether the error disappears. If it does, then the error is in that bit you commented.