Created
June 5, 2019 16:36
-
-
Save matthewspear/aff7aa92874d395ac534a96a2431966a to your computer and use it in GitHub Desktop.
A TableView-Style List in SwiftUI
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 | |
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