Created
January 28, 2020 01:30
-
-
Save duanebester/aa64b76651caa4fb16114d74543b45fb to your computer and use it in GitHub Desktop.
Song List View
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 SwiftUI | |
struct Song: Identifiable, Codable { | |
let id: Int | |
let name: String | |
let artist: String | |
} | |
struct SongListView: View { | |
let names = ["Bailamos", "Dance Monkey", "One in a million", "Waka Waka", "Macarena"] | |
let artists = ["Duane", "Jared", "Zach", "Eduardo", "Miguel"] | |
func getData(number: Int = 20) -> [Song] { | |
var items: [Song] = [] | |
for index in 1...number { | |
items.append(Song(id: index, name: names.randomElement()!, artist: artists.randomElement()!)) | |
} | |
return items | |
} | |
var body: some View { | |
List { | |
ForEach(self.getData()) { song in | |
HStack { | |
Image("\((song.id % 6) + 1)") | |
.resizable() | |
.frame(width: 50, height: 50) | |
.clipped() | |
VStack(alignment: .leading) { | |
Text(song.name) | |
Text(song.artist).font(.caption) | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment