Lacking argument for parameter "consumer" name – SwiftUi


I have been getting this error message within the "ProfileFeedView_Previews" and I couldn’t determine how one can clear up it. Assist can be a lot appreciated.

Error Message: Lacking argument for parameter "consumer" name

Listed here are my codes:


import SwiftUI

struct ProfileFeedView: View {
    @ObservedObject var viewModel: ProfileViewModel
    let columns: [GridItem] = [
        GridItem(.flexible(), spacing: 0, alignment: nil),
        GridItem(.flexible(), spacing: 0, alignment: nil)]
    
    init(consumer: Consumer) {
        self.viewModel = ProfileViewModel(consumer: consumer)
    }
    var physique: some View {

            NavigationView {
                ScrollView{
                    LazyVGrid(columns: columns, spacing: 5) {
                        ForEach(viewModel.folders) { folder in
                            FolderLineItem(folder: folder)
                        }
                    }
                }.navigationTitle("Folders")
                    .navigationBarHidden(true)
                    .padding(.prime, 50)
        }
    }
}

struct ProfileFeedView_Previews: PreviewProvider {
    static var previews: some View {
        ProfileFeedView()


class ProfileViewModel: ObservableObject {
    @Printed var folders = [Folder]()
    personal let service = FolderService()
    let consumer: Consumer
    
    init(consumer: Consumer) {
        self.consumer = consumer
        self.fetchUserFolders()
    }
    
    func fetchUserFolders() {
        guard let uid = consumer.id else { return }
        
        service.fetchUserFolders(forUID: uid) { folders in
            self.folders = folders
            
            for i in 0 ..< folders.depend {
                self.folders[i].consumer = self.consumer
            }
        }
    }
}

struct FolderLineItem: View {
    let folder: Folder
    
    var physique: some View {
        
            VStack {
                Picture("Picture 4")
                    .resizable()
                    .scaledToFill()
                    .body(width: (UIScreen.primary.bounds.width / 2) - 15, peak: (UIScreen.primary.bounds.width / 2) - 15)
                    .clipped()
                    .cornerRadius(8)
                Textual content(folder.foldername)
                    .font(.callout)
                    .lineLimit(2)
                    .padding(.backside, 15)
                    .padding(.trailing, 5)
            
        }
    }
}

struct FolderService {

func fetchUserFolders(forUID uid: String, completion: @escaping([Folder]) -> Void) {
        Firestore.firestore().assortment("folders")
            .whereField("uid", isEqualTo: uid)
            .getDocuments { snapshot, _ in
                guard let paperwork = snapshot?.paperwork else { return }
                let folders = paperwork.compactMap({ attempt? $0.knowledge(as: Folder.self)})
                completion(folders.sorted(by: { $0.timestamp.dateValue() > $1.timestamp.dateValue()}))
            }
    }
}

struct Folder: Identifiable, Decodable {
    @DocumentID var id: String?
    let foldername: String
    let folderdescription: String
    let timestamp: Timestamp
    let uid: String
    
    var consumer: Consumer?
}

I’m misplaced, and couldn’t found out what’s inflicting the error. For context, I’m a beginner and has solely been coding for two months.

See also  Decide when animating UIView is intersecting/overlapping one other view in Swift for iOS

Leave a Reply