I'm trying to make a registration form with multiple views but only one view controller. After proceeding to the next view I'm writing the input to a struct which will be sent to the server later on. The problem I'm facing is that the VC is reinitialized when entering the new view and therefore the user struct is reinitialized too. Is there any way to get around having multiple ViewControllers ?
If the only reason for using one view controller is so that you can persist your data across the different screens you are trying to present, you should probably consider storing your data outside the view controller class. For example by using another class with a shared instance:
class DataContainer {
static let shared = DataContainer()
var someString: String?
}
You can now access the same data from any view controller as follows (without losing the data when moving to another view controller):
if let someString = DataContainer.shared.someString {
print(someString)
}