title: Append text or data to text file in Swift
body: <p>I already have read <a href="https://stackoverflow.com/questions/24097826/read-and-write-data-from-text-file">Read and write data from text file</a>     </p>
  
  <p>I need to append the data (a string) to the end of my text file.<br>
  One obvious way to do it is to read the file from disk and append the string to the end of it and write it back, but it is not efficient, especially if you are dealing with large files and doing in often.     </p>
  
  <p>So the question is "How to append string to the end of a text file, without reading the file and writing the whole thing back"? </p>
  
  <p>so far I have:     </p>
  
  <pre><code>    let dir:NSURL = NSFileManager.defaultManager().URLsForDirectory(NSSearchPathDirectory.CachesDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask).last as NSURL
      let fileurl =  dir.URLByAppendingPathComponent("log.txt")
      var err:NSError?
      // until we find a way to append stuff to files
      if let current_content_of_file = NSString(contentsOfURL: fileurl, encoding: NSUTF8StringEncoding, error: &amp;err) {
          "\(current_content_of_file)\n\(NSDate()) -&gt; \(object)".writeToURL(fileurl, atomically: true, encoding: NSUTF8StringEncoding, error: &amp;err)
      }else {
          "\(NSDate()) -&gt; \(object)".writeToURL(fileurl, atomically: true, encoding: NSUTF8StringEncoding, error: &amp;err)
      }
      if err != nil{
          println("CANNOT LOG: \(err)")
      }
  </code></pre>