Created
July 9, 2023 21:25
-
-
Save marcoarment/9c548fd138a883d9397dacc6c6d3f627 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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