Brand new coder here and first time user. I apologize if this is too easy for most. I am having an issue using the naviationLink to switch from a context view to a detail view. I want to show a row of of guitars and then show a detail view of the guitar chosen from the table.
Here are some details. I have a Guitars.swift file that contains a list of guitars. (See below)
import Foundation
struct Guitars: Identifiable, Hashable {
let id: Int
let name, description, imageName: String
}
let guitar: [Guitars] = [
.init (id: 1, name: "Classical", description: "This is a nylon string guitar that is acoustic and made if cedar or spruce wood", imageName: "classical"),
.init (id: 2, name: "Acoustic", description: "The acoustic guitar is a steel string instrument that is traditionally played as an accompanying part of a musical performance.", imageName: "acoustic"),
.init (id: 3, name: "Electric", description: "This is a steel string guitar that is electic with pickups and made to be played through amplifiers", imageName: "electric_guitar-1"),
.init (id: 4, name: "Banjo", description: "This is a steel string guitar that has five strings. It's usually played in country and bluegrass music", imageName: "banjo"),
.init (id: 5, name: "Bass", description: "This is a steel string guitar that has four strings. It's usually played in all types of bands and provides the bass line for the music", imageName: "bass")
]
I have a guitarDetails file that contains a defined property and a struct. (See below)
struct GuitarDetails: View {
var selectedGuitar: Guitars
var body: some View {
VStack{
Image(selectedGuitar.name)
.resizable()
.frame(width:300, height: 300)
VStack {
Spacer()
}
}
}
}
struct GuitarDetails_Previews: PreviewProvider {
static var previews: some View {
GuitarDetails(selectedGuitar: <#T##Guitars#>)
And lastly, I have a ContentView file where I created the NavigationLink to move from the content view to the detail view but I can't get it to work. Can someone help me out? Here is the content view code.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
List (Guitars) { guitar in
NavigationLink(destination: GuitarDetails(selectedGuitar: guitar) {
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
}
Thee error I get is: "'GuitarDetails.Type' is not convertible to '(Guitars) -> GuitarDetails'