Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created February 23, 2023 09:09
Show Gist options
  • Save Dimillian/fb0c282b055297ddee979322b1acbdd4 to your computer and use it in GitHub Desktop.
Save Dimillian/fb0c282b055297ddee979322b1acbdd4 to your computer and use it in GitHub Desktop.
import SwiftUI
import Combine
struct ContentView: View {
@State var items: [Int] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
var body: some View {
List {
ForEach(items, id: \.self) { item in
Text("Item: \(item)")
}
}
.onReceive(Timer.publish(every: 0.8, on: .main, in: .common).autoconnect()) { _ in
withAnimation {
items.insert(Int.random(in: Int.min..<Int.max), at: 0)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment