Created
June 5, 2019 09:09
-
-
Save rhysm94/6221d2066ccb42d92dbd700a8120cfb2 to your computer and use it in GitHub Desktop.
Runs in a Swift Playground, even on macOS 10.14!
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 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