title: How to persist a file under NSHomeDirectory()?
body: <p>I am using <code>NSKeyedArchiver</code> and <code>NSKeyedUnarchiver</code> to implement cache function for my app.</p>
  
  <p>In order to load the cache file each time the app launches, I store the cache file under <code>NSHomeDirectory()</code>. The code (C function) is as following:</p>
  
  <pre><code>NSString* getArchivePathForId(NSString* modelId)
  {
      NSString *cacheIdentifier = @"CacheIdentifier";
      NSString *archiveDirPath = [NSHomeDirectory() stringByAppendingFormat:@"/tmp/%@/cachedModel/%@", getAppVersion(), cacheIdentifier];
  
      NSError* error;
      if (![[NSFileManager defaultManager] fileExistsAtPath:archiveDirPath]) {
          if (![[NSFileManager defaultManager] createDirectoryAtPath:archiveDirPath
                                     withIntermediateDirectories:YES
                                                      attributes:nil
                                                           error:&amp;error])
          {
              NSLog(@"Create directory tmp/cachedModel directory error: %@", error);
              return nil;
          }
      }
  
      NSString *archivePath = [archiveDirPath stringByAppendingFormat:@"/%@", modelId];
      return archivePath;
  }
  </code></pre>
  
  <p>It works fine as long as the App is running or coming back to live from the background mode. But once the app is terminated and re-run, the cached archive file is deleted.</p>
  
  <p>Is there any way to persist the archive file so that I can load the cache stored last time when the app was launched.</p>
  
  <p>I have already realised that each time the app is launched, the application id part of the <code>NSHomeDirectory()</code> is different. Does this have anything to do with my issue?</p>