-5

I have three ViewController two of them have images and TextFields to input from user, and the third one is to display the first and second data and save it .

How can I temporarily save data entered from the user and when the user finishes all the required steps, a summary of the data is called for viewing and then uploaded to the firebase database?

I'm using Swift 4

rmaddy
  • 314,917
  • 42
  • 532
  • 579
GHAZZWAY
  • 13
  • 5

2 Answers2

1

Define a struct that can hold all of the data the user can enter and that eventually needs to be persisted.

Pass an instance of this struct from view controller to view controller where each controller populates which ever fields it is responsible for.

After the last screen, the struct will contain all of the data. Process it as needed.

The above assumes the user will complete the whole process in one use of your app. If you need to support the ability for the user to start now and finish later (and the app could be killed and restarted in the middle), then this basic idea still works but you need to add code to encode/decode the struct to/from a file. Make your struct Codable and use PropertyListEncoder/Decoder.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Thanks for your reply, I think this solution is very cool but excuse me I need an example so I can implement it – GHAZZWAY Jun 28 '18 at 10:19
  • @GHAZZWAY: search for "passing objects UIViewController" – vikingosegundo Jun 28 '18 at 13:17
  • or start here: https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – vikingosegundo Jun 28 '18 at 13:19
  • @GHAZZWAY We are not here to do all of your work. What part of this process do you need help with? Break the problem down into pieces. Start with the struct. Then work on passing the struct to each controller. Then work on filling in part of the struct in each controller. Then work on using the completed data. – rmaddy Jun 28 '18 at 15:42
  • thanks , but i stop in passing the struct to each controller how i do that ? – GHAZZWAY Jun 28 '18 at 16:18
  • Read https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers?noredirect=1&lq=1 – rmaddy Jun 28 '18 at 16:22
-3

all type of Data store in UserDefaults

Like - Float , Double, Int , Bool, URL ...

Description here

UserDefaults.standard.set("Value", forKey: "key")

Get Value

UserDefaults.standard.string(forKey: "key")
Vishal Vaghasiya
  • 4,618
  • 3
  • 29
  • 40
  • but this will save data in local all the time i just want save data temporarily when user done from input all data will display and he press a button to save in data base and thats temporarily data disappear – GHAZZWAY Jun 27 '18 at 14:14
  • you can store data in global variable then after click on save button to set data – Vishal Vaghasiya Jun 27 '18 at 14:16