Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Last active January 10, 2021 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IhwanID/53aee0b59f9dc69503e0d177297e7e8f to your computer and use it in GitHub Desktop.
Save IhwanID/53aee0b59f9dc69503e0d177297e7e8f to your computer and use it in GitHub Desktop.
SwiftUI List
struct ContentView: View {
var body: some View {
let rangga = Student(name: "Rangga", age: 18)
let andi = Student(name: "Andi",age: 19)
let ihwan = Student(name: "Ihwan", age: 20)
let students = [rangga, andi, ihwan]
return List(students) { student in
StudentRow(student: student)
}
}
}
struct Student: Identifiable {
var id = UUID()
var name: String
var age: Int
}
struct StudentRow: View {
var student: Student
var body: some View {
Text("\(student.name) - \(student.age) tahun")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment