0

So I have a main uiviewcontroller and it goes down three levels with sub controllers. I am loading a list of data in the main top level uiviewcontroller and passing that down each level which works fine.

I need to load more data for each item in the list. Right now I am loading that data on the fly when the lowest level view gets loaded. I need to load some of this data in the background in the top level view which is fine but I find myself loading this data twice if the current view hadn't been loaded yet. I am thinking of using a global variable (a list) to load all of this data and just use that in each of the subviews. I feel like the global variable is not the way this should be done.

How can I load data in the top level view and have that propagate down to the lowest level views that have already been displayed?

Tyler
  • 2,346
  • 6
  • 33
  • 59
  • possible duplicate of [How do you share data between view controllers and other objects in Swift?](http://stackoverflow.com/questions/29734954/how-do-you-share-data-between-view-controllers-and-other-objects-in-swift) – nhgrif May 12 '15 at 00:11

1 Answers1

0

There are various ways to handle this.

Having to set up links to pass data along each step gets old after a while. When I'm writing an app that needs to share information across multiple levels of view controllers, I'll think seriously about using a data container singleton. See this SO thread for a description of several options, along with a link to a developer blog including a working example of a Swift-based data container singleton:

How do you share data between view controllers and other objects in Swift?

Community
  • 1
  • 1
Duncan C
  • 128,072
  • 22
  • 173
  • 272