2007-03-11 19:28:02 +00:00
|
|
|
/* Copyright (c) 2007 Christopher J. W. Lloyd
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
|
|
|
|
#import <Foundation/NSCoder.h>
|
2007-04-10 16:31:07 +00:00
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
2020-05-11 15:52:05 +00:00
|
|
|
#import <Foundation/NSKeyedUnarchiver.h>
|
2007-04-10 16:31:07 +00:00
|
|
|
#import <Foundation/NSRaise.h>
|
2020-05-11 15:52:05 +00:00
|
|
|
#import <Foundation/NSSortDescriptor.h>
|
|
|
|
#import <Foundation/NSString.h>
|
2006-12-22 04:41:44 +00:00
|
|
|
|
- Renamed&Moved the NSXML* classes into NSPropertyList/NSOldXML*. These are being replaced by classes that adhere to the API documentation but are still needed to read plists while the new classes are being worked on.
- Added method starting points for NSXML*, NSOpenGL*, NSSegmented*, NSNib, NSURLRequest,NSURLResponse,NSURLConnection,NSURLAuthenticationChallenge,NSHTTPURLResponse,NSShadow,NSClassDescription
- Added blank starting points for NSIndexPath,NSValueTransformer,NSNetService*,NSDistributed*,NSDatePicker*,NSSortDescriptor,NSMetadata*,NSDecimal*
- Moved NSAffineTransform into Foundation/
- Changed KGImage_context into KGLayer
2007-03-19 02:52:21 +00:00
|
|
|
@implementation NSSortDescriptor
|
2006-12-22 04:41:44 +00:00
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
+ sortDescriptorWithKey: (NSString *) key ascending: (BOOL) ascending {
|
|
|
|
return [[[NSSortDescriptor allocWithZone: NULL] initWithKey: key
|
|
|
|
ascending: ascending
|
|
|
|
selector: NULL]
|
2020-05-12 18:51:39 +00:00
|
|
|
autorelease];
|
2020-05-11 15:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ sortDescriptorWithKey: (NSString *) key
|
|
|
|
ascending: (BOOL) ascending
|
2020-05-12 00:04:26 +00:00
|
|
|
selector: (SEL) selector
|
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
return [[[NSSortDescriptor allocWithZone: NULL] initWithKey: key
|
|
|
|
ascending: ascending
|
|
|
|
selector: selector]
|
2020-05-12 18:51:39 +00:00
|
|
|
autorelease];
|
2010-10-20 15:05:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- initWithKey: (NSString *) key ascending: (BOOL) ascending {
|
|
|
|
return [self initWithKey: key ascending: ascending selector: NULL];
|
2010-10-20 15:05:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- initWithKey: (NSString *) key
|
2020-05-12 18:51:39 +00:00
|
|
|
ascending: (BOOL) ascending
|
|
|
|
selector: (SEL) selector
|
2020-05-12 00:04:26 +00:00
|
|
|
{
|
2020-05-11 15:52:05 +00:00
|
|
|
_key = [key copy];
|
|
|
|
_ascending = ascending;
|
|
|
|
|
|
|
|
if (selector == NULL) // Yes it does this
|
|
|
|
_selector = @selector(compare:);
|
|
|
|
else
|
|
|
|
_selector = selector;
|
|
|
|
return self;
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (void) dealloc {
|
|
|
|
[_key release];
|
|
|
|
[super dealloc];
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- copyWithZone: (NSZone *) zone {
|
|
|
|
return [self retain];
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSString *) key {
|
|
|
|
return _key;
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (BOOL) ascending {
|
|
|
|
return _ascending;
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (SEL) selector {
|
|
|
|
return _selector;
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (NSComparisonResult) compareObject: first toObject: second {
|
|
|
|
id checkFirst = [first valueForKeyPath: _key];
|
|
|
|
id checkSecond = [second valueForKeyPath: _key];
|
|
|
|
NSComparisonResult result;
|
|
|
|
|
|
|
|
if (_ascending)
|
|
|
|
result = (NSComparisonResult) [checkFirst performSelector: _selector
|
|
|
|
withObject: checkSecond];
|
|
|
|
else
|
|
|
|
result = (NSComparisonResult) [checkSecond performSelector: _selector
|
|
|
|
withObject: checkFirst];
|
|
|
|
|
|
|
|
return result;
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- reversedSortDescriptor {
|
|
|
|
return [[[[self class] alloc] initWithKey: _key
|
|
|
|
ascending: !_ascending
|
|
|
|
selector: _selector] autorelease];
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder *) coder {
|
|
|
|
if ([coder allowsKeyedCoding]) {
|
|
|
|
[coder encodeObject: _key forKey: @"Key"];
|
|
|
|
[coder encodeBool: _ascending forKey: @"Ascending"];
|
|
|
|
[coder encodeObject: NSStringFromSelector(_selector)
|
|
|
|
forKey: @"Selector"];
|
|
|
|
} else {
|
|
|
|
[coder encodeObject: _key];
|
|
|
|
[coder encodeValueOfObjCType: @encode(BOOL) at: &_ascending];
|
|
|
|
[coder encodeObject: NSStringFromSelector(_selector)];
|
|
|
|
}
|
2007-04-10 16:31:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 15:52:05 +00:00
|
|
|
- (id) initWithCoder: (NSCoder *) coder {
|
|
|
|
if ([coder allowsKeyedCoding]) {
|
|
|
|
NSKeyedUnarchiver *keyed = (NSKeyedUnarchiver *) coder;
|
|
|
|
_key = [[keyed decodeObjectForKey: @"Key"] copy];
|
|
|
|
_ascending = [keyed decodeBoolForKey: @"Ascending"];
|
|
|
|
_selector =
|
2020-05-12 18:51:39 +00:00
|
|
|
NSSelectorFromString([keyed decodeObjectForKey: @"Selector"]);
|
2020-05-11 15:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
_key = [[coder decodeObject] copy];
|
|
|
|
[coder decodeValueOfObjCType: @encode(BOOL) at: &_ascending];
|
|
|
|
_selector = NSSelectorFromString([coder decodeObject]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2007-05-14 13:15:31 +00:00
|
|
|
}
|
|
|
|
|
2006-12-22 04:41:44 +00:00
|
|
|
@end
|