-1

I am trying to get ContentView() from the following code from course view.

.sheet(isPresented: self.$showContent) {ContentView()}

Here is full code:

//
//  HomeList.swift
//  Design Code
//
//  Created by Govind Pathak on 09/09/19.
//  Copyright © 2019 Govind Pathak. All rights reserved.
//

import SwiftUI

struct HomeList: View {
    @State var showContent = false
    var body: some View {
        ScrollView(.horizontal , showsIndicators: false){
            HStack(spacing:30) {
                ForEach(courses) { item in
                    CourseView(
                        title: item.title,
                        image: item.image,
                        color: item.color,
                        shadowColor: item.shadowColor)
                        .sheet(isPresented: self.$showContent) {ContentView()}
                }
            } .padding(.leading , 30)
        }
    }
}
struct HomeList_Previews: PreviewProvider {
    static var previews: some View {
        HomeList()
    }
}
    struct CourseView: View {
    // @Environment(\.presentationMode) var presentationMode

    var title = "Build an app with SwiftUI"
    var image = "Illustration1"
    var color = Color("background3")
    var shadowColor = Color(red: 0.271, green: 0.235, blue: 0.788, opacity: 0.3)
    var body: some View {
        VStack(alignment: .leading) {
            Text(title)
                .font(.title)
                .fontWeight(.bold)
                .foregroundColor(Color.white)
                .padding(20)
                .lineLimit(4)
                .padding(.trailing , 50)


            Spacer()
            Image(image)
                .resizable()
                .renderingMode(.original)
                .aspectRatio(contentMode: .fit)
                .frame(width: 246, height: 150)
                .padding(.bottom , 30)
        }
        .background(color)
        .cornerRadius(30)
        .frame(width: 246, height: 360)
        .shadow(color:shadowColor , radius: 20 , x: 0, y: 20)
    }
}
struct Course : Identifiable {
    var id = UUID()
    var title: String
    var image: String
    var color: Color
    var shadowColor: Color
}
let coursesData = [
    Course(title: "Build an app with SwiftUI",
           image: "Illustration1",
           color: Color("background3"),
           shadowColor: Color("backgroundShadow3")),
    Course(title: "Design Course",
           image: "Illustration2",
           color: Color("background4"),
           shadowColor: Color("backgroundShadow4"))
]

var courses = coursesData
Benjamin Kindle
  • 1,736
  • 12
  • 23

1 Answers1

0

First of all you are trying to iterate over a list of courses in your HomeList using for each, but courses are not defined anywhere.

This line:

.sheet(isPresented: self.$showContent) { ContentView() }

should go as the last thing before you close the brackets on the body declaration.

You also need a way to change showContent value to true.

LuLuGaGa
  • 13,089
  • 6
  • 49
  • 57
  • Please check the code full below. I have defined them. let coursesData = [ Course(title: "Build an app with SwiftUI", image: "Illustration1", color: Color("background3"), shadowColor: Color("backgroundShadow3")), Course(title: "Design Course", image: "Illustration2", color: Color("background4"), shadowColor: Color("backgroundShadow4")) ] – Govind Pathak Sep 10 '19 at 04:48
  • You have defined courseData outside the struct you are trying to use them in. – LuLuGaGa Sep 11 '19 at 06:30