title: Check difference between stored file and file accessed by URL
body: <p>I'm new to Swift programming, and trying to sort out in my head (and my code) the best practice for the following situation: </p>
  
  <p>My app accesses data from a simple txt file (merely 2KB) on a server when it loads. I'd prefer to not bundle this file with my app so I can edit the data as needed without requiring the user to update the app each time this data source is refreshed.</p>
  
  <p>Further, I'd prefer my app did not require access to this file on its server each time it loads. Therefore, I'd like the app to, upon the very first time it is opened, access the file (I have this function working) and then store the data file on the phone, thus not requiring an Internet connection upon each launch.</p>
  
  <p>The issue I can't solve (and extensive Googling hasn't provide much insight for) is how I could check when my app launches if its stored data file is different in comparison to the one located on the server. Then, if different, it could download and replace the data on the phone with the most recent data file. </p>
  
  <p>I'm looking at using the Core Data API for storing the txt file locally. Any help advice or other questions that may have answered this I didn't locate are appreciated.</p>
  
  <p><strong>>>>UPDATE (02/06/16) &lt;&lt;&lt;</strong></p>
  
  <p>Here is the solution that I've ended up with, in pseudocode (or my version of pseudocode...). If anyone is interested in my actual solution, I'd be more than willing to share.</p>
  
  <pre><code>identify name of file on phone AS phoneFile
  
  if phoneFile does NOT exist
      create phoneFile
      retrieveData online and overwrite phoneFile with onlineData
  else 
      immediately loadData from phoneFile (allowing app to be functional)
      dispatch asynchronous function (in background while data loads from phoneFile)
      {
          if phoneFile != onlineData
              update phoneFile, overwriting with onlineData
              prompt user requesting to refresh data in application
          else
              do nothing
       }
  </code></pre>
  
  <p>Hopefully that makes sense. Essentially, the first time we open the app there is no file on the phone, so we wait for the download and then run app with that data.</p>
  
  <p>Each subsequent time however, we open the app with the data on the phone, and in the background check if there is new data online. My file online is only 1KB so there is not a significant download, but this method helps prevent slow app loading if the network connection is slow or interrupted.</p>
  
  <p>Also, I mentioned this in comments below, but I utilized file save functions found on this tutorial here: <a href="http://learncoredata.com/how-to-save-files-to-disk" rel="nofollow">learncoredata.com/how-to-save-files-to-disk</a></p>