Created
August 3, 2019 23:19
-
-
Save PaulWoodIII/8e9fce0cb696c1d431ec29aa77de9778 to your computer and use it in GitHub Desktop.
A Simple list that uses the Identifiable protocol
This file contains hidden or 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 Name: Identifiable, ExpressibleByStringLiteral { | |
| var name: String | |
| public init(stringLiteral value: Swift.StringLiteralType) { | |
| self.name = value | |
| } | |
| var id: String { return name } | |
| } | |
| let names: [Name] = [ | |
| "Alice", | |
| "Bob", | |
| "Charlotte", | |
| "David", | |
| "Elanore", | |
| "Frank", | |
| "Georgia", | |
| "Howard" | |
| ] | |
| struct SimpleIdentifiableList : View { | |
| var body: some View { | |
| List(names) { name in | |
| Text(name.name) | |
| } | |
| } | |
| } | |
| let viewController = UIHostingController(rootView: SimpleIdentifiableList()) | |
| PlaygroundPage.current.liveView = viewController |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment