There is concept of Pass By Value & Pass By Reference
.
Best fit solution for your question is to use Pass By Reference
type.
If we talk about Swift programming language
.
class
are Reference type & struct
are Value type.
So, your model class should be build up with class
type.
Code example.
class Dog {
var breed : String = ""
var sub_breed = [String]()
init(_breed:String,_sub_breed:[String]) {
self.breed = _breed
self.sub_breed = _sub_breed
}
}
FirstViewController:
var dogs : [Dog] = [Dog(_breed: “Original”, _sub_breed: [“subBreedType1”, “subBreedType2”])]
SecondViewController: // You are passing reference of dogs to SecondVC
var dogs : [Dog] = []
dogs[0].breed = “Modified”
Now you have changed value of breed name
from SecondViewController
, if you go back to FirstViewController
and check the first element
of array the value will be “Modified”
You can try this idea.
Other solutions : Singleton object
of your Model class
.
Thank you.