title: Save and Load Custom Dictionary - NSUserDefaults
body: <p>I have an <code>[Int:Bool]</code> dictionary and I am trying to save it into my NSDictionary.. However, it crashes with error <code>Attempt to set a non-property-list object</code></p>
  
  <pre><code>let dictionary = [Int:Bool]()
  
  
  self.dictionary[2] = true
  self.dictionary[3] = false
  
  NSUserDefaults.standardUserDefaults().setObject(dictionary, forKey: "dictionary")
  </code></pre>
  
  <hr>
  
  <p>Also, for loading, first I tried this but error logged it strictly requires AnyObject?.</p>
  
  <pre><code>NSUserDefaults.standardUserDefaults().objectForKey("dictionary")
  </code></pre>
  
  <p>Then I tried this and it logged: </p>
  
  <pre><code>NSUserDefaults.standardUserDefaults().objectForKey("dictionary") as? [Int:Bool]
  </code></pre>
  
  <p>I also tried <code>dictionaryForKey</code>. I got..</p>
  
  <pre><code>NSUserDefaults.standardUserDefaults().dictionaryForKey("dictionary")
  </code></pre>
  
  <blockquote>
    <p>Cannot assign value to type [String: AnyObject] to type [Int:Bool]</p>
  </blockquote>
  
  <hr>
  
  <p>So which one of these 2 is a better approach to take? (The values would be optional in my case I think)</p>
  
  <pre><code>1.
  NSUserDefaults.standardUserDefaults().objectForKey("dictionary") as? [Int:Bool] ?? [Int:Bool]()
  
  2.
  NSUserDefaults.standardUserDefaults().objectForKey("dictionary") as? [Int:Bool])!
  </code></pre>