34 lines
1 KiB
Swift
34 lines
1 KiB
Swift
import Portico
|
|
|
|
private struct Item: Identifiable { let id: Int; let title: String }
|
|
|
|
struct ListDemo: View {
|
|
@State private var items = [Item(id: 1, title: "One"),
|
|
Item(id: 2, title: "Two"),
|
|
Item(id: 3, title: "Three")]
|
|
@State private var next = 4
|
|
|
|
var body: some View {
|
|
VStack(spacing: 12) {
|
|
HStack(spacing: 12) {
|
|
Button("Add") { items.append(Item(id: next, title: "Item \(next)")); next += 1 }
|
|
Button("Remove first") { if !items.isEmpty { items.removeFirst() } }
|
|
Button("Reverse") { items.reverse() }
|
|
}
|
|
ForEach($items, id: \.id) { item in
|
|
Label(item.title)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@main
|
|
struct ExampleApp: App {
|
|
var applicationId: String? { "dev.bscubed.PorticoExample" }
|
|
|
|
var body: some Scene {
|
|
Window { _ in ListDemo() }
|
|
.title("Portico P4 — ForEach")
|
|
.defaultSize(width: 1280, height: 800)
|
|
}
|
|
}
|