My question is a bit confused. I've a ViewController that shows to the user some attributes, these attributes are in a dictionary. For edit these attributes I've another ViewController, that when I "segue" to that I pass the attributes in the default way, like this:
viewController.value = self.value
On the second ViewController (view controller of edition) I've options to Back to ViewController and Save the changes, so, I can change values without save or save. When I change values and not save, just back to view controller, the value is changed in the previous view controller. I don't understannd how this happens. I will try show with images.
My first view controller is: ViewContollerSale.swift
My second (edit) view controller is: ViewControllerCreateSale.swift
ViewControllerSale.swift
var saleOrder : SaleOrder? // at this point it's populated
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("===> VcSale: prepare")
if segue.identifier == "segueEditOrder" {
print("segue: segueEditOrder")
let editVc = segue.destination as! ViewControllerCreateSale
editVc.saleToEdit = true
if saleOrder != nil {
editVc.sale = saleOrder!
}
}
}
ViewControllerCreateSale.swift
The function that set value is showed below. But I think that this changes only value of instance context of ViewControllerCreateSale.swift, but when I back view controller the value is changed also on the previous view controller!
var sale: SaleOrder = SaleOrder()
case Notification.Name.opEntrega:
aux = notf.object as! String
sale.attributes["delivery_term_id"] = aux == "CIF" ? Int32(1) : Int32(2)
let cell = tableOptionsSelect.cellForRow(at: IndexPath(row: 3, section: 0)) as! CellSelectionCreateSale
cell.lblOptionSelect.text = aux
break