> 
> *Background: In order to make web requests to an API endpoint, I need to scrape a website and retrieve a token every 25-30 seconds. I'm doing this with a [WKWebView](https://developer.apple.com/documentation/webkit/wkwebview) and injecting some custom JavaScript using [WKUserScript](https://developer.apple.com/documentation/webkit/wkuserscript) to retrieve AJAX response headers containing the token. Please focus on the question specifically and not on this background information - I'm attempting this entirely for my own educational purposes.*
> 
> 
> 

Goal
----

I will have different 'model' classes, or even just other *UIViewControllers*, that may need to call the shared *UIViewController* to retrieve this token to make an authenticated request.

Maybe I might abstract this into one "Sdk" class. Regardless, this 'model' SDK class could be instantiated and used by any other *ViewController*.

More info
---------

I would like to be able to call the *UIViewController* of the *WKWebView* and retrieve some data. Unless I re-create it every 25 seconds, I need to run it in the background or share it. I would like to be able to run a *UIViewController* 'in the background' and receive some information from it once *WKWebView* has done it's thing. 

I know there are multiple ways of communicating with another *ViewController* including delegation and segueing. However, I'm not sure that these help me keep the view containing the *WKWebView* existing in the background so I can call it's *ViewController* and have it re-perform the scrape. Delegation may work for normal code, but what about one that must have the view existing? Would I have to re-create this *WKWebView* dynamically each time a different model, or view controller, were to try and get this token?

[One post](https://useyourloaf.com/blog/container-view-controllers/) suggests utilising *ContainerViewControllers*. From this, I gather that in the 'master' *ViewController* (the one containing the other ones), I could place the hidden *WKWebView* to do it's thing and communicate to the child view controllers that way via delegation.

Another post suggests using *AppDelegate* and making it a shared service. I'm completely against using a **Singleton** as it is widely considered an anti-pattern. There must be another way, even if a little more complex, that helps me do what I want without resorting to this 'cheat'.

[This post](https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers?rq=1) talks about communicating between multiple *ViewControllers*, but I can't figure out how this would be useful when something needs to stay running and executing things.

How about any other ways to do this? Run something in a background thread with a strong pointer so it doesn't get discarded? I'm using Xcode 9.2, Swift 4, and iOS 11. As I'm very new to iOS programming, any small code examples on this would be appreciated.