So I have to pass instance of my custom class from one UIViewController
to another:
targetVC.reservation = self.reservation!
print(self.reservation!.id, "before")
targetVC.reservation!.phoneNumber = self.phoneTextField.text!.phoneToString()
targetVC.reservation!.id = id
print(self.reservation!.id, "after")
My problem is that self.reservation!.id
is also changed: "before" it is ""
, and "after" it is id
. Why does it happen and how to avoid this?
You can use
mutableCopy()
with your object but for that your custom class need to extends fromNSObject
and its return type isAny
so you need to explicitly type cast its result to yourCustomClass
.