I understand how to pass simple data (e.g. Structures, Ints, Strings, Floats) between one view controller to another through properties. However, I get stumped when passing an active URLsession from one view controller to another.
Scenario, I have a task that starts uploading potential (large size) content from one view controller and needs to move to another ViewController most likely before the URLsession.shared.dataTask is completed. However, I need the URLsession to remain persistent and update the app when it's completed. I have thought of using a singleton for this case and saw that singletons are not the best way to go about things, but should work. I am fine with making a separate completion handler to handle the task in the other ViewController, but I am not quite sure how to actually implement this via code. It would be really nice if someone could post an example.
For now, just so that is is working, I am doing a one time thing and putting the task in the AppDelegate file. This is not recommended, but for one task it will work for now.
Also, I am aware of the "container" method, I do not want to put it in a container view controller at this time because it is a part of an onboarding process. So, I would prefer to pass it at this moment.
I am unsure about:
Will a URLsession that is initiated in one ViewController continue to run on the background thread even if the ViewController it is initiated on is destroyed?
If the answer is yes to that question, how do I go about accessing the response to the call or hearing that it's completed.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…