NEW: Learn to build amazing SwiftUI apps for macOS with my new book! >>

'Item' not in scope.

Forums > SwiftUI

Hey y'all. I got this error here that Item is not in scope when I am trying to make a navigation link.

import SwiftUI

struct Membership: View {
    var body: some View {
        NavigationView{
            List{

                MembershipView(plan: "Standard", price: "FREE", icon: "Normal")
                MembershipView(plan: "Bronze", price: "$1.99", icon: "Ladoo")
                MembershipView(plan: "Silver", price: "$5.99", icon: "Silver")
                MembershipView(plan: "Gold", price: "$9.99", icon: "Gold")
                MembershipView(plan: "Diamond", price: "$11.99", icon: "Diamond")
                MembershipView(plan: "Platinum", price: "$15.99", icon: "Platinum")
                MembershipView(plan: "Titanium", price: "$19.99", icon: "Samosa")

                }
            NavigationLink(
            destination: MemberDetailView(member: item)) {//ERROR
                                MembershipView()
            }
            .navigationTitle("Membership Plans")
        }//: NAVIGATION
    }
}

struct Membership_Previews: PreviewProvider {
    static var previews: some View {
        Membership()
    }
}

Please Help.

1      

What is item and where does it come from? You need a property or something in Membership to supply a value for item.

1      

@roosterboy

So what should I put instead of "item"?

1      

Well, it depends on what goes in your MemberDetailView. But whatever it is, it needs to come from somewhere, either initialized within Membership itself or passed into it from outside.

1      

It now works Thank You!

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Spend less time managing in-app purchase infrastructure so you can focus on building your app. RevenueCat gives everything you need to easily implement, manage, and analyze in-app purchases and subscriptions without managing servers or writing backend code.

Get Started

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.