Skip to content

Instantly share code, notes, and snippets.

@hajipy
Created April 14, 2012 10:38
Show Gist options
  • Save hajipy/2383469 to your computer and use it in GitHub Desktop.
Save hajipy/2383469 to your computer and use it in GitHub Desktop.
// managedObjectModelからFetchedPropertyを検索し、ソート条件を追加
// NSPersistentStoreCoordinatorを作成する前に行うこと!
for (NSEntityDescription* entity in [managedObjectModel entities]) {
for (NSPropertyDescription* property in [entity properties]) {
if ([property isKindOfClass:[NSFetchedPropertyDescription class]]) {
NSFetchedPropertyDescription* fetchedProperty = (NSFetchedPropertyDescription*) property;
NSFetchRequest* fetchRequest = [fetchedProperty fetchRequest];
if ([[[[fetchRequest entity] propertiesByName] allKeys] containsObject:@"twId"]) {
NSSortDescriptor* sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"twId" ascending:NO] autorelease];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment