title: iOS - Attempt to insert non-property list object NSDictionary in NSUserDefaults
body: <p>In my app, I need to save my custom <code>User</code> object <code>NSDictionary</code> in my <code>NSUserDefaults</code>. I attempt this with the following code:</p>
  
  <pre><code>NSDictionary *userObjectDictionary = response[@"user"];
  NSLog(@"USER OBJECT:\n%@", userObjectDictionary);
  [defaults setObject:userObjectDictionary forKey:@"defaultUserObjectDictionary"];
  [defaults synchronize];
  </code></pre>
  
  <p>This attempt crashes my app with the following message:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception
    'NSInvalidArgumentException', reason: 'Attempt to insert non-property
    list object {type =
    immutable dict, count = 10, entries =>    0 : status_id =     1 : {contents = "first_name"} = exampleFirstName    3 : id = {value = +2, type =
    kCFNumberSInt64Type}  4 : {contents = "profile_picture"} = {contents =
    "<a href="http://myDevServer.com/pictures/userName.jpg" rel="noreferrer">http://myDevServer.com/pictures/userName.jpg</a>"}   5 :
    last_name = exampleLastName   7 : email = {contents = "myEmail@gmail.com"}    8 : {contents = "badge_count"} = {value = +0, type =
    kCFNumberSInt64Type}  9 : user_name = userName    10 : {contents = "phone_number"} = {contents = "0123456789"}    12 : {contents = "status_updated_at"} =
     }  for key
    defaultUserObjectDictionary'</p>
  </blockquote>
  
  <p>This is what my <code>User</code> object dictionary looks like before I attempt to save it:</p>
  
  <pre><code>{
      "badge_count" = 0;
      email = "myEmail@gmail.com";
      "first_name" = exampleFirstName;
      id = 2;
      "last_name" = exampleLastName;
      "phone_number" = 0123456789;
      "profile_picture" = "http://myDevServer.com/pictures/userName.jpg";
      "status_id" = "&lt;null&gt;";
      "status_updated_at" = "&lt;null&gt;";
      "user_name" = userName;
  }
  </code></pre>
  
  <p>Is it crashing because there a null values in my <code>User</code> object <code>NSDictionary</code>? I tried with a regular <code>NSDictionary</code> with dummy data with null values and it worked. If this is the problem, how to I bypass this? Sometimes my <code>User</code> object will have properties that are nullable.</p>