title: NSSortDescriptor for NSFetchRequest sorting unexpectedly
body: <p>My entity has a property (sortOrder) that is of the type Decimal(NSDecimalNumber) but when I execute a fetch request using that property as a key, I get back results in a seemingly random order.  If I output the value of the property I get really strange values until I get it's intValue.</p>
  
  <p>Example:  The first run produces this result.  The first value is the raw value of the property.  The second is the intValue, the actual value of the property when I created the object - or at least I thought.</p>
  
  <p>85438160 10</p>
  
  <p>74691424 20</p>
  
  <p>Second run...</p>
  
  <p>85333744 10</p>
  
  <p>85339168 20</p>
  
  <p>Third...</p>
  
  <p>85263696 20</p>
  
  <p>85269568 10</p>
  
  <p>What the hell?</p>
  
  <p>Fetch Request:</p>
  
  <pre><code>NSMutableArray *cats = [[NSMutableArray alloc] initWithArray:[CoreDataHelper searchObjectsInContext:@"RestaurantMenuCategory":nil:@"sortOrder":YES:NO:nil]];
  </code></pre>
  
  <p>Here is the searchObjectsInContext method from my CoreDataHelperClass:</p>
  
  <pre><code>+(NSMutableArray *) searchObjectsInContext: (NSString*)entityName : (NSPredicate *)predicate : (NSString*)sortKey : (BOOL)sortAscending : (BOOL)distinct : (NSString*)distinctProperty
  {
      RestaurantController *ctrl = [RestaurantController sharedRestaurantController];
  
      NSFetchRequest *request = [[NSFetchRequest alloc] init];
      NSEntityDescription *entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:ctrl.managedObjectContext];
      [request setEntity:entity];
  
      if(distinct==YES){
          [request setReturnsDistinctResults:YES];
      }
  
      if(distinctProperty!= nil){
          [request setPropertiesToFetch :[NSArray arrayWithObjects:distinctProperty,nil]];
      }
  
      if(predicate != nil){
          [request setPredicate:predicate];
      }
  
      if(sortKey != nil){
          NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:sortAscending];
          NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
         [request setSortDescriptors:sortDescriptors];
         [sortDescriptors release];
         [sortDescriptor release];
     }
  
     NSError *error;
  
     NSMutableArray *mutableFetchResults = [[[ctrl.managedObjectContext executeFetchRequest:request error:&amp;error] mutableCopy] autorelease];
  
     [request release];
  
     return mutableFetchResults;
  }
  </code></pre>