This is pretty standard stuff, any tutorial on core data has it, the only tricks are that I pass in NSStrings for table names, and that I don't put it in my application delegate. The source for this can be found @
Original header
Original Source
Extending set to get a sorted array
// An extension of NSSet to get a sorted array from that set.
@interface NSSet(ArrayMethods)
- (NSArray*) getSortedArray:(NSString*) primaryKey;
@end
@implementation NSSet(ArrayMethods)
- (NSArray*) getSortedArray:(NSString*) primaryKey
{
NSSortDescriptor *sortDesc =
[[NSSortDescriptor alloc] initWithKey:primaryKey
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:) ];
NSArray *descArray=[[NSArray alloc] initWithObjects:sortDesc,nil] ;
NSArray *returnValue=[[self allObjects] sortedArrayUsingDescriptors:descArray] ;
[descArray release];
[sortDesc release];
return returnValue ;
}
@end
No comments:
Post a Comment