import SwiftUI
struct ContentView: View {
@State var numbers = [Int]()
@State var currentNumber = 1
var body: some View {
NavigationView {
VStack {
List {
ForEach(numbers, id:\.self) {
Text("\($0)")
}.onDelete(perform: removeRows)
}
Button("Add Number") {
self.numbers.append(currentNumber)
currentNumber += 1;
}
}
}.navigationBarItems(leading: EditButton())
}
func removeRows(at offsets: IndexSet) {
numbers.remove(atOffsets: offsets)
}
}
From: SwiftUI 知识碎片