title: How to check NSCache instance value set or not
body: <p>I have an instance of <code>NSCache</code>, like: <code>NSCache *imageCache;</code> It is basically used for holding some remote "image" values with different <code>"@keys"</code>. I <code>alloc</code> &amp; <code>init</code> <code>NSCache</code> in a Global class at the beginning and set a <code>if else</code> condition, like this:</p>
  
  <pre><code>if (self.imageCache == nil)
  {
      self.imageCache = [[NSCache alloc] init];
  }
  else
  {
      NSLog(@"cache set");
  }
  </code></pre>
  
  <p>I <code>#import</code> that "Global Class" in all of <code>ViewControllers</code>, so that I don't have to parse images every time. But the problem is when I go to other <code>ViewControllers</code> It seems like, <code>NSCache</code> <code>alloc</code> &amp; <code>init</code> every time. Because It takes same time to load the images as <code>1stVC</code>. I think the <code>if else</code> condition didn't working perfectly or it's not the appropriate way to check either <code>NSCache</code> set or not.
  Can anyone tell me whats wrong with it? One thing more, The <code>imageCache</code> is used from a global variable.<br/>
  Thanks in advance.<br/>
  Have a good day.</p>
  
  <p><strong>ADDITION:</strong></p>
  
  <p>This is the method where I load the <code>UIButtons</code> in <code>UIScrollView</code> as <code>subView</code>. This is a <code>UIViewClass</code> which I add in my "EveryViewController" as a <code>subView</code> Just take have a look on the <code>if (cachedImage)</code> line. It works fine. But when I want to check either the <code>NSCache</code> (iADImageCache) set or not, it shows me it's not set. But which should be set. In this situation how can I check all several <code>iADImageCache</code> with their different <code>@"Key"</code> name?
  Thanks again.</p>
  
  <pre><code>-(void) loadUIButton
  {
      [self loadScrollView];
      for (int i = 0; i &lt; [iADDisplayArray count]; i++)
      {
          adButtonOutLet = [[UIButton alloc] initWithFrame:CGRectMake(i*320, 0, ButtonWidth, ButtonHight)];
  
          currentAd = [iADDisplayArray objectAtIndex:i];
  
          NSString *path = currentAd.bannerIconURL;
          NSURL *url = [NSURL URLWithString:path];
          NSMutableURLRequest *requestWithBodyParams = [NSMutableURLRequest requestWithURL:url];
          NSData *imageData = [NSURLConnection sendSynchronousRequest:requestWithBodyParams returningResponse:nil error:nil];
          UIImage *originalImage = [UIImage imageWithData:imageData];
  
          UIImage *cachedImage =  [self.iADImageCache objectForKey:currentAd.bannerIconURL];
          if (cachedImage)
          {
              [adButtonOutLet setImage:cachedImage forState:UIControlStateNormal];
              //NSLog(@"OnecachedImage %@", cachedImage);
          }
          else
          {
              [self.iADImageCache setObject:originalImage forKey:currentAd.bannerIconURL];
              [adButtonOutLet setImage:originalImage forState:UIControlStateNormal];
              NSLog(@"OneimageCache %@", self.iADImageCache);
          }
  
          adButtonOutLet.userInteractionEnabled= YES;
          [adButtonOutLet setTag:i];
          [adButtonOutLet addTarget:self action:@selector(goToURL:) forControlEvents:UIControlEventTouchUpInside];
  
          [self.iADScrollView addSubview:adButtonOutLet];
      }
  }
  </code></pre>