Added missing Mac OS X 10.6 methods related to NSSortDescriptor

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37689 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
qmathe 2014-02-14 13:02:41 +00:00
parent feddbf6a1b
commit 2dd421fbff
3 changed files with 63 additions and 0 deletions

View file

@ -1,3 +1,12 @@
2014-02-14 Quentin Mathe <quentin.mathe@gmail.com>
* Headers/Foundation/NSSortDescriptor.h
* Source/Foundation/NSSortDescriptor.m
(+sortDescriptorWithKey:ascending:selector:,
+sortDescriptorWithKey:ascending,
-[NSSet sortedArrayUsingDescriptors:]): Added missing Mac OS X 10.6
methods.
2014-02-13 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSFormat.m: Fix to cope with cases where a format specifies

View file

@ -30,6 +30,7 @@
#import <Foundation/NSObject.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSSet.h>
#if defined(__cplusplus)
extern "C" {
@ -74,6 +75,25 @@ extern "C" {
*/
- (NSComparisonResult) compareObject: (id)object1 toObject: (id)object2;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
/** Returns an autoreleased sort descriptor for comparisons using the
* 'compare:' selector and the specified key and ordering.
*
* See also -initWithKey:ascending:.
*/
+ (id) sortDescriptorWithKey: (NSString *)aKey ascending: (BOOL)ascending;
/** Returns an autoreleased sort descriptor initialized to perform comparisons
* in the specified order using aSelector to compare the property aKey of each
* object.
*
* See also -initWithKey:ascending:selector:.
*/
+ (id) sortDescriptorWithKey: (NSString *)aKey
ascending: (BOOL)ascending
selector: (SEL)aSelector;
#endif
/** Initialises the receiver for comparisons using the 'compare:' selector
* and the specified key and ordering.
*/
@ -129,6 +149,16 @@ extern "C" {
@end
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6,GS_API_LATEST)
@interface NSSet (NSSortDescriptorSorting)
/**
* Produces a sorted array from using the mechanism described for
* [NSMutableArray-sortUsingDescriptors:]
*/
- (NSArray *) sortedArrayUsingDescriptors: (NSArray *)sortDescriptors;
@end
#endif
#if defined(__cplusplus)
}
#endif

View file

@ -121,6 +121,20 @@ static BOOL initialized = NO;
return _ascending + GSPrivateHash(0, sel, strlen(sel)) + [_key hash];
}
+ (id) sortDescriptorWithKey: (NSString *)aKey ascending: (BOOL)ascending
{
return AUTORELEASE([[self alloc] initWithKey: aKey ascending: ascending]);
}
+ (id) sortDescriptorWithKey: (NSString *)aKey
ascending: (BOOL)ascending
selector: (SEL)aSelector
{
return AUTORELEASE([[self alloc] initWithKey: aKey
ascending: ascending
selector: aSelector]);
}
- (id) initWithKey: (NSString *) key ascending: (BOOL) ascending
{
return [self initWithKey: key ascending: ascending selector: NULL];
@ -449,3 +463,13 @@ SortRange(id *objects, NSRange range, id *descriptors,
}
@end
@implementation NSSet (NSSortDescriptorSorting)
- (NSArray *) sortedArrayUsingDescriptors: (NSArray *)sortDescriptors
{
return [[self allObjects] sortedArrayUsingDescriptors: sortDescriptors];
}
@end