title: Determine whether NSManagedObject attribute is optional
body: <p>I am using Core Data and have a subclass of <code>NSManagedObject</code> called <code>Person</code> (which is an entity in Core Data). The Person object has several properties (e.g. <code>firstName</code>, <code>lastName</code>, etc.) and relationships (e.g. <code>friends</code>, <code>coWorkers</code>). Some of these attributes are optional, whereas others are mandatory.</p>
  
  <p>Given a <code>Person</code> object how can I efficiently determine whether a particular property or relationship is optional or mandatory?</p>
  
  <p>I want to try and avoid having to do some kind of inefficient loop through each attribute of the Person object, as I will need to call the code fairly often, so something similar to the pseudocode below would be perfect:</p>
  
  <pre><code>if ( [[aPerson getProperty:@"firstName"] isOptional] ) {
  
      // do stuff
  
  }
  </code></pre>
  
  <p>...but I am not sure whether it could be done that simply. The above pseudocode would also only check properties, so I am guessing something else would need to be done in case the attribute being checked is a relationship.</p>
  
  <p>I realize that it is probably more efficient to do a single loop and store the name of all the mandatory attributes in an array (then just check that array for the presence of the attribute name) and that's what I am doing at the moment, but unfortunately it doesn't really work with the structure of my code (thus the need for a more "on-demand" approach).</p>
  
  <p>Any help would be greatly appreciated :)</p>