I have a Function addNote() that returns a value called 'idd' in the form of string
Now I have a view called ListView where there is a navigationLink that essentially needs that returned 'idd' value to be passed to this view called NoteView which is that navigationLink's destination. However I'm not able to pass that value down to NoteView.
I've been struggling with this for days now, I'd appreciate if someone could give me their two cents! Thanks a ton.
here’s the listview code:
` structure ListView: View {
@StateObject var dataManager = DataManager()
@State var isPresented = false
var body: some View {
NavigationView {
ZStack{
List(dataManager.notes) { note in
NavigationLink(destination: NoteView(newNote: note.content, idd: note.id)) {
EmptyView()
Text(note.content)}.buttonStyle(PlainButtonStyle())
.frame(height: 0)
.navigationTitle("Notes")
.navigationBarItems(
trailing: Button (action: {},
label: {
NavigationLink(destination: NoteView(newNote: "", idd: "") )
{Image(systemName: "plus")}
.simultaneousGesture(TapGesture().onEnded{
dataManager.addNote()
})}
))
.listStyle(.plain)
.buttonStyle(PlainButtonStyle()) ‘
here’s the idd that addNote() returns:
`class DataManager : ObservableObject {
@Published var notes: [Note] = []
@Published var idd = ""
func addNote()-> String{
let user = Auth.auth().currentUser
let uid = Auth.auth().currentUser!.uid
let db = Firestore.firestore()
var ref: DocumentReference? = nil
ref = db.collection("userslist").document(uid).collection("actualnotes").addDocument(data: ["content":"New Note"])
{error in
if let error = error{
print(error.localizedDescription)
}
else {
print("Document added with ID: \(ref!.documentID)")
}
}
let idd = ref!.documentID
return idd
}`