xcode - Unwind segue isn't editing a selected cell but keeps appending to the array -


so i'm working on contacts page , want able select cell , edit data. contacts information appears in contact page, particular contact being sent. it's when hit save creates new contact instead of modifying selected one.

@ibaction func unwindtocontacts(sender: uistoryboardsegue) {      if let sourceviewcontroller = sender.sourceviewcontroller as? newcontactviewcontroller, contact = sourceviewcontroller.contact {         if let selectedindexpath = tableview.indexpathforselectedrow {             // update existing contact.             contacts[selectedindexpath.row] = contact             tableview.reloadrowsatindexpaths([selectedindexpath], withrowanimation: .none)         } else {             // add new contact.             let newindexpath = nsindexpath(forrow: contacts.count, insection: 0)             contacts.append(contact)             tableview.insertrowsatindexpaths([newindexpath], withrowanimation: .bottom)         }         // save contacts.         {             try managedcontext.save()         }         catch let error nserror{             print("error: \(error)" + "description: \(error.localizeddescription)")         }     } } 

edit: solved keeping track of nsindexpath , passing , from.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -