我正在学习Swift,并尝试实现WWDC 2019 Session 204中演示的“ Room”应用。在下面的代码中,该代码与视频中的Jacob完全相同,但是遇到以下错误:
行:
.onDelete(perform: deleteRoom)
错误:
“调用中的外部参数标签'perform:'”
不能自己弄清楚...
谢谢!
struct ContentView: View {
//var rooms: [Room] = []
// @ObservedObject var store = RoomStore()
var store = RoomStore()
var body: some View {
NavigationView {
List {
Section {
Button(action: addRoom) {
Text("Add")
}
}
Section {
ForEach(store.rooms) { room in
RoomCell(room: room)
}
/* HERE is the error */
.onDelete(perform: deleteRoom)
}
}
.navigationBarTitle(Text("Rooms"))
.listStyle(.grouped)
}
}
func addRoom() {
store.rooms.append(Room(name: "New Room", capacity: 20, hasVideo: true))
}
func deleteRoom(at offsets: IndexSet) {
store.rooms.remove(atOffsets: offsets)
}
}