Friday, February 16, 2024
HomeiOS DevelopmentLacking argument for parameter 'time' in name error when working program

Lacking argument for parameter ‘time’ in name error when working program


I’m making this medicine app for a challenge and it retains giving these errors 3 instances subsequent to the app whereas I run it will probably somebody assist me please.

! THIS IS THE .swift file above the content material view



import SwiftUI

struct DEMOAApp: App {
    let sampleMedicines: [Medicine] = [
        Medicine(name: "Aspirin", dosage: "1 tablet", schedule: "Morning", purpose: "Pain relief"),
        Medicine(name: "Ibuprofen", dosage: "1 tablet", schedule: "Afternoon", purpose: "Anti-inflammatory"),
        Medicine(name: "Acetaminophen", dosage: "1 tablet", schedule: "Evening", purpose: "Fever reducer")
    ]

    var physique: some Scene {
        WindowGroup {
            ContentView(medicines: sampleMedicines)
        }
    }
}

THIS IS THE CONTENT VIEW FILE

import SwiftUI

struct Drugs: Identifiable {
    var id = UUID()
    var title: String
    var dosage: String
    var schedule: String
    var objective: String
    var time: Date // Added time property
    
    // Methodology to verify if the medication is scheduled for a specific day
    func timeIsOnDay(_ dayIndex: Int) -> Bool {
        let calendar = Calendar.present
        let medicationDay = calendar.element(.weekday, from: time) - 1 // Regulate for 0-based indexing
        return dayIndex == medicationDay
    }
}

// Pattern information for testing
let sampleMedicines: [Medicine] = [
    Medicine(name: "Aspirin", dosage: "1 tablet", schedule: "Morning", purpose: "Pain relief", time: Date()),
    Medicine(name: "Ibuprofen", dosage: "1 tablet", schedule: "Afternoon", purpose: "Anti-inflammatory", time: Date()),
    Medicine(name: "Acetaminophen", dosage: "1 tablet", schedule: "Evening", purpose: "Fever reducer", time: Date())
]

struct ContentView: View {
    var medicines: [Medicine]

    var physique: some View {
        NavigationView {
            Listing(medicines, id: .id) { drugs in
                NavigationLink(vacation spot: MedicineDetailView(drugs: drugs)) {
                    VStack(alignment: .main) {
                        Textual content(drugs.title)
                            .font(.headline)
                        Textual content("Dosage: (drugs.dosage)")
                        Textual content("Schedule: (drugs.schedule)")
                        Textual content("Objective: (drugs.objective)")
                    }
                }
            }
            .navigationTitle("Drugs")
        }
    }
}

struct MedicineDetailView: View {
    let drugs: Drugs

    var physique: some View {
        VStack(alignment: .main) {
            Textual content(drugs.title)
                .font(.title)
            Textual content("Dosage: (drugs.dosage)")
            Textual content("Schedule: (drugs.schedule)")
            Textual content("Objective: (drugs.objective)")
        }
        .padding()
        .navigationTitle(drugs.title)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView(medicines: sampleMedicines)
    }
}

I attempted to maneuver the code round and tried many suggestions and methods discovered on-line. They didn’t work



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments