title: Persisting class instance in other class while populating the UIProgressView
body: <p>I have been using <strong>NSURLSession</strong> to download files and storing them in directory and everything is working fine using objective C and XCode 7.3 . I use an <strong>UIProgressView</strong> to show the progress of the download session. But when I try to modularise the code and separate the <strong>NSURLSessionDelegate</strong> methods from the <strong>UIViewController</strong> class , I am unable to use it . </p>
  
  <p><strong>Problem Description</strong> :</p>
  
  <p><strong>Class A</strong> : <strong>UIViewController</strong> class which has a table view and a progress View . </p>
  
  <p><strong>Class B</strong> : <strong>NSObject</strong> class which has a method to start the download session (Class A's instance is passed as a parameter to this class's method)</p>
  
  <p><strong>Class C</strong> : NSObject class which implements the <strong>NSURLSessionDelegate</strong>  methods and need to populate the progressView in Class A using <strong>SetProgress:</strong> (Unable to do so as I am unable to pass the Class A's instance to Class C and can only create a new instance which isn't going to help)</p>
  
  <p>When I put all the code in one class , it works like charm ! And I tried using protocol but was still unable to do so . So , any help on the same would be appreciated. Thanks in advance. </p>
  
  <p>Edit 1 : Class C code : </p>
  
  <pre><code>-(void) setDelegateForProgressView :(id) delegate {
  self.docCatalogInstancePersist = delegate;
  }
  - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite{
  NSString *downloadInProgress = ENABLED;
  self.docCatalogInstancePersist.progressView.hidden= NO;
  
  [[NSUserDefaults standardUserDefaults] setObject:downloadInProgress forKey:@"downloadInProgress"];
  [[NSUserDefaults standardUserDefaults] synchronize];
  dispatch_async(dispatch_get_main_queue(), ^{
      [self.docCatalogInstancePersist.progressView setProgress:(double)totalBytesWritten/(double)totalBytesExpectedToWrite
                                               animated:YES];    });
  
  
  }
  </code></pre>