BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

'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 In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

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.