Cannot convert value of type 'Task.Type' to expected argument type 'Task'

Hi, I am SWIFT newbie. I am trying for the first app in iOS with below codes. I am facing error "Cannot convert value of type 'Task.Type' to expected argument type 'Task'" in the last line of the DetailsView.swift. Please help to explain and fix. Thanks very much.

Content view:

import SwiftUI

let afternoonTask = [

    Task(name: "Make home work - Science", isComplete: false, lastCompleted: nil),

    Task(name: "Make home work - Math", isComplete: false, lastCompleted: nil),

    Task(name: "Make home work - Social", isComplete: false, lastCompleted: nil),

    Task(name: "Make home work - Project", isComplete: false, lastCompleted: nil),

    Task(name: "Make home work - Communication", isComplete: false, lastCompleted: nil)

]

let morningTask = [

    Task(name: "Make home work - Math VN", isComplete: false, lastCompleted: nil),

    Task(name: "Make home work - Vietnamses", isComplete: false, lastCompleted: nil)

]

let weekendTask = [

    Task(name: "Make remain home work", isComplete: false, lastCompleted: nil)

]

struct ContentView: View {

    var body: some View {

//        List (afternoonTask, id: .self, rowContent: {taskName in Text (taskName)

//        })

        NavigationView {

            List {

                Section(header: TaskSectionHeader(symbolSystemName: "sunset", headerText: "Afternoon Wed to Fri Task")) {

                    ForEach(afternoonTask, content: { task in NavigationLink (task.name, destination: DetailsView(task: task))

                    })

                }

                

                Section(header: TaskSectionHeader(symbolSystemName: "sunrise", headerText: "Morning Thu to Fri Task")) {

                    ForEach(morningTask, content: { task in NavigationLink (task.name, destination: DetailsView(task: task))

                    })

                }

                Section(header: TaskSectionHeader (symbolSystemName: "calendar", headerText: "Weekend Remain Task")) {

                    ForEach(weekendTask, content: { task in NavigationLink (task.name, destination: DetailsView(task: task))

                    })

                }

            }.listStyle(GroupedListStyle())

            .navigationTitle("Spring Hill Schedule")

        }

    }

}

struct TaskSectionHeader: View {

    let symbolSystemName: String

    let headerText: String

    

    var body: some View {

        HStack {

            Image(systemName: symbolSystemName)

            Text(headerText)

        }

        .font(/@START_MENU_TOKEN@/.title3/@END_MENU_TOKEN@/)

    }

}

struct ContentView_Previews: PreviewProvider {

    static var previews: some View {

        ContentView()

    }

}

DetailsView

import SwiftUI

struct DetailsView: View {

    let task: Task

    

    var body: some View {

        VStack {

            Text(task.name)

            Text("All the homework for morning section from Mon to Wed")

            //EmptyView()

        }

    }

}

struct DetailsView_Previews: PreviewProvider {

    static var previews: some View {

        DetailsView(task: Task)

    }

Task

import Foundation

struct Task: Identifiable {

    let id = UUID()

    let name: String

    var isComplete: Bool

    var lastCompleted: Date?

}

}

Please use the Code Block feature of this site when showing your code.

(Or you can enclose each code block with lines containing only ``` manually.)


And the last line of the DetailsView.swift in your shown code is a closing brace (}) and it lacks another closing brace.

I guess the line you get the error is:

        DetailsView(task: Task)

Then the cause of the error is obvious.

When you use DetailsView(task:), you need to pass an instance of Task to the parameter task:, but you are just writing the type name Task.

Please try changing the line as follows:

        DetailsView(task: Task(name: "Make home work - Science", isComplete: false, lastCompleted: nil))

{The site was malfunctioning -- removed.}

Cannot convert value of type 'Task.Type' to expected argument type 'Task'
 
 
Q