Skip to content

Instantly share code, notes, and snippets.

@matthewspear
Created June 5, 2019 16:36
Show Gist options
  • Save matthewspear/aff7aa92874d395ac534a96a2431966a to your computer and use it in GitHub Desktop.
Save matthewspear/aff7aa92874d395ac534a96a2431966a to your computer and use it in GitHub Desktop.
A TableView-Style List in SwiftUI
import SwiftUI
import PlaygroundSupport
struct Contact: Identifiable {
// important for each to be unique
var id = UUID()
var name: String
}
struct MyTableView: View {
let contacts: [Contact] = [
Contact(name: "Matt"),
Contact(name: "Andy"),
Contact(name: "Hubert")
]
var body: some View {
List(contacts) { contact in
Text(contact.name)
}
}
}
PlaygroundPage.current.liveView = UIHostingController(rootView: MyTableView())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment