Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Last active October 28, 2024 16:02
Show Gist options
  • Save takoikatakotako/d694f238e324cfb215a76a1a58b74c23 to your computer and use it in GitHub Desktop.
Save takoikatakotako/d694f238e324cfb215a76a1a58b74c23 to your computer and use it in GitHub Desktop.
Identifiableに適合していないStructでListを使う
import SwiftUI
struct ContentView: View {
let pokemons: [Pokemon] = [
Pokemon(name: "snorlax", type: "normal"),
Pokemon(name: "ditto", type: "normal"),
Pokemon(name: "psyduck", type: "water"),
Pokemon(name: "pikachu", type: "electric"),
]
var body: some View {
List {
ForEach(0..<pokemons.count, id: \.self) { index in
Text("\(pokemons[index].name)")
}
}
}
}
import SwiftUI
struct Pokemon {
let name: String
let type: String
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment