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

'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.

2      

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

2      

@roosterboy

So what should I put instead of "item"?

2      

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.

2      

It now works Thank You!

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.

Learn more here

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.