Код: Выделить всё
import SwiftUI
import AVKit
struct Song: Identifiable {
let id = UUID()
let title: String
let artist: String
let image: String
let mp3FileName: String
}
struct MusicView: View {
let songs: [Song] = [
Song(title: "Warriors", artist: "Imagine Dragons", image: "warriors", mp3FileName: "Warriors (ft. Imagine Dragons)"),
// other songs
]
var body: some View {
ScrollView {
VStack {
ForEach(songs) { song in
HStack {
Image(song.image) // Error here Argument type 'String' does not conform to expected type 'Decoder
.resizable()
.scaledToFit()
.frame(width: 80, height: 80)
.cornerRadius(10)
VStack(alignment: .leading) {
Text(song.title)
.font(.headline)
Text(song.artist)
.font(.subheadline)
}
Spacer()
}
.padding()
Divider()
}
}
}
}
}
- Я проверил, что имена изображений в ресурсы точно совпадают с изображениями в моем каталоге ресурсов.
- Я подтвердил, что изображения существуют в каталоге ресурсов.
Я ожидаю, что изображения будут отображаться рядом с названиями песен и исполнителями.
Ошибка:
Код: Выделить всё
Argument type 'String' does not conform to expected type 'Decoder' on Image(song.image)
Подробнее здесь: https://stackoverflow.com/questions/791 ... en-using-i