Skip to content

Instantly share code, notes, and snippets.

@marcoarment
Created July 9, 2023 21:25
Show Gist options
  • Save marcoarment/9c548fd138a883d9397dacc6c6d3f627 to your computer and use it in GitHub Desktop.
Save marcoarment/9c548fd138a883d9397dacc6c6d3f627 to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
@State var numbers = [1, 2, 3, 4, 5, 6, 7, 8]
var body: some View {
Button {
withAnimation {
numbers.append(Int.random(in: 9..<99))
numbers.sort()
}
} label: {
Label("Add", systemImage: "plus")
}
List {
ForEach(numbers, id: \.self) { n in
HStack {
Text("\(n)")
Spacer()
Button {
withAnimation {
if let idx = numbers.firstIndex(of: n) {
numbers.remove(at: idx)
}
}
} label: {
Label("Delete", systemImage: "trash")
}
}
.transition(.move(edge: .leading))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment