Last active
January 10, 2021 01:13
-
-
Save IhwanID/53aee0b59f9dc69503e0d177297e7e8f to your computer and use it in GitHub Desktop.
SwiftUI List
This file contains 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
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) | |
} | |
} | |
} |
This file contains 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
struct Student: Identifiable { | |
var id = UUID() | |
var name: String | |
var age: Int | |
} |
This file contains 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
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