1

I'm developing an app which handles some downloads in the background. I move the file to the documents directory and save it under the original name (using downloadTask.originalRequest?.URL!.pathExtension). So far so good.

Using

URLSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:) 

I can print out the progress in the console while downloading. But this doesn't help me if I'm using the App on the phone. What I'm expecting to do is to call a function to update a progress bar from here within my View that was initialising the download. But I have no idea how to call it.

Does anybody know how I can find out from which UIViewController (actually most of the time it will be a TableCellViewController) I started the download and how to send the progress to a function of that ViewController?

SnareChops
  • 13,175
  • 9
  • 69
  • 91
Holger
  • 356
  • 4
  • 11

2 Answers2

1

I 'd like to tell you a good tutorial about this question. NSURLSession Tutorial

Arco
  • 614
  • 5
  • 13
  • Thanks, I'm going to try to implement it that way. – Holger Feb 07 '16 at 21:00
  • It took me the complete evening. But: It works and I think I understand delegates now better than before. Thanks a lot! – Holger Feb 08 '16 at 21:18
  • if I had the time… it's a 'just for fun' project I'm working on. In my normal job I don't have anything to do with coding (maybe just a little bit python or VB Excel Macros - usual business casper stuff) – Holger Feb 09 '16 at 06:09
  • Last year, I started to learn Swift with no-experience about programming. I am grade to help you. You can chat with me in Twitter. The same ID @Lanaya_HSIEH. – Arco Feb 09 '16 at 07:48
0

Delegates are often used in the following situations

When a class needs to communicate some information to another class When a class wants to allow another class to customize it The classes don't need to know anything about each other beforehand except that the delegate class conforms to the required protocol.

I the following article you can see how to create a delegate in objective-C and Swift 2.0.

How do I create delegates in Objective-C?

Community
  • 1
  • 1
Jose Pose S
  • 1,175
  • 17
  • 33
  • if is good for you i can build a proyect with an example but tell me if you want this. – Jose Pose S Feb 07 '16 at 11:17
  • Thanks, I'm actually delegating the download task to a download manager class. What I'm missing is the information back from the delegate to the delegator. I'll try to implement it like in the tutorial linked by Lanaya. – Holger Feb 07 '16 at 20:59