UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Error message at "Cannot find 'GrubbView(userId:)' in scope", how do I fix this?

Forums > SwiftUI

List(items) {

                    items in
                    GrubbItemView(item: items)
                        .swipeActions{
                            Button("Delete"){
                                viewModel.delete(id: items.id)
                            }
                            .tint(.red)
                        }
                }
                .listStyle(DefaultListStyle())
            }
            .navigationTitle("Home (Grubb View)")
            .toolbar{
                Button {
                    // Action
                    viewModel.showingNewItemView = true
                } label: {
                    Image(systemName: "plus")
                }
            }
            .sheet(isPresented: $viewModel.showingNewItemView) {
                NewItemView(NewItemShown: $viewModel.showingNewItemView)
            }
        }
    }
}

Preview {

GrubbView(userId: )

}

Preview {

GrubbView(userId: )     "Cannot find 'GrubbView(userId:)' in scope"

}

Hello, i'm having trouble with fixing this error, pls help?

2      

@alan is out of scope and seeks advice:

Hello, i'm having trouble with fixing this error, pls help?

First, welcome to HackingWIthSwift! Keep asking questions. We've all been down this path (some of us more than once!) and the things that trip you up aren't always intuitively obvious.

Second, please review your message above. You can edit it. But please note that not ALL your code is within the mark-up tags. To help us review your code, please make sure ALL your code is formatted properly.

Next think about how you can easily break a complicated application screen (a view) into many smaller parts. To see all the parts working together, you probably run your application in a simulator. This catches all user swipes, taps and keyboard entries and orchestrates the data, updating your terriffic user interface.

But consider how you might design just a small part of your over all interface. For example, how might you design a single row in your list view?

Here's some sample code to illustrate.

struct Decoration { // not a view.
    // just a box containing related data.
    var symbol: String = "headlight.high.beam.fill"
    var label:  String = "lights on"

    // This is a static box containing test data. Use it in examples!
    static var sample = Decoration(symbol: "moonphase.waxing.crescent", label: "Waxing Moon")
}

struct RowView: View {
    // Row will display a Decoration object
    // by default, none is provided
    // To display, I NEED A DECORATION OBJECT
    var decoration: Decoration // <-- This is a variable

    // body is ALSO a variable, but it's a calculated variable.
    // You can't initialise it.
    var body: some View {
        HStack(alignment: .firstTextBaseline) {
            Image(systemName: decoration.symbol)
            Text("\(decoration.label)")
        }.font(.largeTitle)
    }
}

// ---------------------------------------------- Preview the View in Xcode 15
#Preview {
    RowView()  // <-- Missing argument

    // This isn't your application. It's a preview of a single row object.
    // But for the view to draw itself, it needs a fake Decoration object
    RowView(decoration: Decoration.sample) // <-- Provide a fake Decoration object
}

Keep Coding

2      

You show us a List extracted from a larger View. Please show us the entire View that is having the problem.

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Click to save your free spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.