// 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];
return returnValue ;
}
@end
There are probably better ways to do this, and I might find a memory error in there at some point in time,(although I think I have it right).
No comments:
Post a Comment