Making a new View with same functionality as other views but with different content

I have a tasks/notes app in the form of a list that when I add a task, I give it a title, for example “Groceries". I want to be able to click “groceries" and for there to appear a new list with new notes that would be such as beverages or food. Such notes would be added by the user. 

Then in the main section if I want to add a new task or notes such as “Chores” ,when I click on chores it takes me to a new page in which the user can add chores. 

However, right now I only know how to take it to the same view. So in other words, if i click on “groceries", I will see the same as if I click on “Chores”. In my app, it takes me to exampleView as you can see below.

My app is made around core data, what I essentially want is for when I click a note such as groceries or chores, I can have a page in which I store new notes. 

How can I make it so when I click on a note on the main page, it takes me to a new page?

Any advice, tutorials, or anything helps. Thank You.

ForEach(notesVM.notes, id: \.id){note in
         NavigationLink(destination: exampleView()){
         NotesCell(note: note)
        }

This is what I Have:

This is what I Want:

I suggest the following.

  1. Passing argument, identifier of title, to your second page. (If user use unique title in your app, you can use title as an identifier.)
  2. Then, setting NSPredicate with argument.

An example:

import SwiftUI

import CoreData





struct exampleView: View {

    @Environment(\.managedObjectContext) private var viewContext

    @FetchRequest(

        sortDescriptors: [],

        animation: .default)

    private var items: FetchedResults<YourClass>

    

    var title: String

    

    @State var isReady = false // When finish setting nsPredicate, turn true and show list.

    

    var body: some View {

        List{

            if isReady {

                ForEach(items){item in

                    Text(item.yourProperty)

                }

            }

        }

        .onAppear(perform: { search(str: self.title) })

    }

    

    

    private func search(str: String){

        if str.isEmpty {

            items.nsPredicate = nil

        } else {

            let predicate = NSPredicate(format: "title contains %@", str)

            items.nsPredicate = predicate

        }

        isReady = true // Show list

    }

}

And in your main page:

ForEach(notesVM.notes, id: \.id){note in

    NavigationLink(destination: exampleView(title: "groceries")){

        NotesCell(note: note)

    }

}

I don't know details of your CoreData object. So please customize it yourself for your project.

At last, I apologize if my English is incorrect because I'm not a native English speaker.

Making a new View with same functionality as other views but with different content
 
 
Q