title: Delete key values for NSUserDefaults in Swift
body: <p>How to delete data from NSUserDefaults? There is quite a few answers how to do it in Objective C, but how about Swift?
  So I tried this:</p>
  
  <pre><code>let defaults = NSUserDefaults.standardUserDefaults()
      defaults.removeObjectForKey("myKey")
  </code></pre>
  
  <p>Didn't work. Maybe what I really want to delete is not NSUserDefaults?
  This is how I save data:</p>
  
  <pre><code>class MySavedData: NSObject, NSCoding {
      var image: String
  
      init(name: String, image: String) {
          self.image = image
      }
  
      required init(coder aDecoder: NSCoder) {
          image = aDecoder.decodeObjectForKey("image") as! String
      }
  
      func encodeWithCoder(aCoder: NSCoder) {
          aCoder.encodeObject(image, forKey: "image")
      }
  }
  
  class ViewController: &lt;...&gt; {
      var myData = [MySavedData]() //Later myData gets modified and then function save() is called
  
      func save() {
          let savedData = NSKeyedArchiver.archivedDataWithRootObject(myData)
          let defaults = NSUserDefaults.standardUserDefaults()
          defaults.setObject(savedData, forKey: "myKey")
      }
  }
  </code></pre>
  
  <p><strong>EDIT:</strong> Just to clear some things - data that is being saved is small (not even close to 100kb)</p>
  
  <p>And maybe I am saving data not to NSUserDefaults (I am new to programming), so here is how I get it (load):</p>
  
  <pre><code>let defaults = NSUserDefaults.standardUserDefaults()
  if let savedData = defaults.objectForKey("myData") as? NSData {
      myData = NSKeyedUnarchiver.unarchiveObjectWithData(savedData) as! [UserLogin]
      }
  </code></pre>