0

What I want to do:

I have two ViewControllers, both contain tableViews.

In the first ViewController the users chooses a Name from the tableViewCell and that should get stored int the tableView in the second ViewController.

Right now I do this by appending the tableViewCell content to an array in the second ViewController.

My problem:

By that method I can only get 1 tableViewCell to the array in the second ViewController, since it doesnt save the previous added Cells.

My idea:

I think some kind of local database could solve my issue, but I have absolutely no clue where to start or what to look for.

Can you help me?

Jan Swoboda
  • 152
  • 2
  • 15
  • You can keep your collection in your first view controller. When going to the second view controller pass the collection to it and when dismiss just send it back to the first view controller. Google for delegates. Another option is to use a singleton. – Leo Dabus Aug 26 '20 at 00:47
  • Just keep it inside instance variable and pass it by what ever way the best fit to your dev pattern. Just keep in mind, please don't use singleton pattern if that is the use case. – MatthewLuiHK Aug 26 '20 at 02:51

1 Answers1

0

I think you are looking for UserDefaults. This is how you can store data locally for Swift, so that it isn't deleted upon exiting out of the app. (Unless the app itself is deleted)

See this link for another similarly answered question: How can I use UserDefaults in Swift?

I would refer you to this resource as well for more information on UserDefaults: https://www.hackingwithswift.com/read/12/2/reading-and-writing-basics-userdefaults

CodeMan123
  • 35
  • 7