title: NSManagedObject - How to get the type of the property
body: <p>I am trying to parse a json string straight into a managed object.
  The json string contains all strings, but my Entity has Date objects.</p>
  
  <p>if this is my json string</p>
  
  <pre><code>{
  "name":"John",
  "dob": "12/12/2008",
  etc...
  }
  </code></pre>
  
  <p>and here's my entity Person:</p>
  
  <pre><code>name : NSString
  dob: Date
  etc...
  </code></pre>
  
  <p>I want to parse that json straight through by looping through the keys of the Json dict, and setting the values to the matching keys of my entity:</p>
  
  <pre><code>Person *aPerson = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:managedObjectContext];
  NSArray *keys = [jsonDict allKeys];
  
  for (NSString *key in keys) {
  
   [aPerson setValue:[jsonDict valueForKey:key] forKey:key];
  
  }
  </code></pre>
  
  <p>This only works if all my entity's properties are NSStrings.</p>
  
  <p>How can I get the type/class of my entity's property to be able to set the various types?</p>
  
  <p>eg.
  if key = @"dob"
  how can I get the type/class of aPerson.dob?</p>
  
  <p>so my code will look something like:</p>
  
  <pre><code>Person *aPerson = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:managedObjectContext];
  NSArray *keys = [jsonDict allKeys];
  
  for (NSString *key in keys) {
      if([[aPerson objectForKey:key] isKindOfClass:[NSDate class]])
      {
         // Create an NSDate object
      }else{
         [aPerson setValue:[jsonDict valueForKey:key] forKey:key];
      }
  }
  </code></pre>
  
  <p>thanks</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Ok I tried using the isKindOfClass and here's the result was:</p>
  
  <pre><code>// for key = @"name" 
  // aPerson.name is NSString
  [[aPerson valueForKey:key] isKindOfClass:[NSString class]] =&gt; TRUE
  [[aPerson valueForKey:key] isKindOfClass:[NSObject class]] =&gt; TRUE
  
  // for key = @"age"
  // aPerson.age is NSNumber
  [[aPerson valueForKey:key] isKindOfClass:[NSNumber class]] =&gt; TRUE
  [[aPerson valueForKey:key] isKindOfClass:[NSObject class]] =&gt; TRUE
  
  // for key = @"dob"
  // aPerson.dob is NSDate
  [[aPerson valueForKey:key] isKindOfClass:[NSDate class]] =&gt; FALSE
  [[aPerson valueForKey:key] isKindOfClass:[NSObject class]] =&gt; FALSE
  </code></pre>
  
  <p>how is that? 
  @dynamic dob and NSDate, is notOfClass NSDate!</p>
  
  <p>please tell me what I am missing!</p>