title: How do I create an NSFetchedPropertyDescription programmatically?
body: <p>I have a pre-existing <code>NSManagedObjectModel</code> that I created with the Xcode GUI.  I want to create a sorted fetched property, which Xcode 3.2's GUI doesn't support.  I do all of this before creating my <code>NSPersistentStoreCoordinator</code> because I know you can't modify a <code>NSManagedObjectModel</code> after an object graph manager has started using it.  I created the <code>NSFetchedPropertyDescription</code> thusly:</p>
  
  <pre><code>NSManagedObjectModel *managedObjectModel = ... // fetch from my mainBundle
  
  NSEntityDescription *fetchedPropertyEntityDescription = [entitiesByName objectForKey:@"MyEntity"];
  
  NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
  [fetchRequest setEntity:fetchedPropertyEntityDescription];
  [fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"myPredicateProperty == $FETCH_SOURCE"]];
  [fetchRequest setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"mySortProperty" ascending:YES]]];
  
  NSFetchedPropertyDescription *fetchedPropertyDescription = [[[NSFetchedPropertyDescription alloc] init] autorelease];
  [fetchedPropertyDescription setFetchRequest:fetchRequest];
  [fetchedPropertyDescription setName:@"myFetchedProperty"];
  
  NSEntityDescription *entityDescription = [entitiesByName objectForKey:@"MyFetchSourceEntity"];
  
  [entityDescription setProperties:[[entityDescription properties] arrayByAddingObject:fetchedPropertyDescription]];
  </code></pre>
  
  <p>When I call</p>
  
  <pre><code>[fetchedPropertyDescription setFetchRequest:fetchRequest];
  </code></pre>
  
  <p>I get the following exception:</p>
  
  <pre><code>NSInvalidArgumentException: Can't use fetch request with fetched property description (entity model mismatch).
  </code></pre>