Skip to content

Instantly share code, notes, and snippets.

@rhysm94
Created June 5, 2019 09:09
Show Gist options
  • Save rhysm94/6221d2066ccb42d92dbd700a8120cfb2 to your computer and use it in GitHub Desktop.
Save rhysm94/6221d2066ccb42d92dbd700a8120cfb2 to your computer and use it in GitHub Desktop.
Runs in a Swift Playground, even on macOS 10.14!
import PlaygroundSupport
import SwiftUI
struct Pokemon {
let dexNum: Int
let species: String
}
extension Pokemon: Identifiable {
var id: Int { return dexNum }
}
struct SpeciesView: View {
var species: Pokemon
var body: some View {
HStack(alignment: .center, spacing: 0) {
HStack {
Text(String(format: "#%03d", species.dexNum))
Spacer()
Text(species.species)
}
}
}
}
struct MyView: View {
var items: [Pokemon]
var body: some View {
List(items, rowContent: SpeciesView.init)
}
}
let pokemon = [
Pokemon(dexNum: 1, species: "Bulbasaur"),
Pokemon(dexNum: 4, species: "Charmander"),
Pokemon(dexNum: 7, species: "Squirtle"),
Pokemon(dexNum: 25, species: "Pikachu"),
Pokemon(dexNum: 133, species: "Eevee"),
Pokemon(dexNum: 150, species: "Mewtwo"),
Pokemon(dexNum: 151, species: "Mew"),
]
PlaygroundPage.current.liveView = UIHostingController(rootView: MyView(items: pokemon))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment