Skip to content

Instantly share code, notes, and snippets.

@PaulWoodIII
Created August 3, 2019 23:19
Show Gist options
  • Select an option

  • Save PaulWoodIII/8e9fce0cb696c1d431ec29aa77de9778 to your computer and use it in GitHub Desktop.

Select an option

Save PaulWoodIII/8e9fce0cb696c1d431ec29aa77de9778 to your computer and use it in GitHub Desktop.
A Simple list that uses the Identifiable protocol
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