Re: Core Data, NSOutlineView and NSSortDescriptors
Re: Core Data, NSOutlineView and NSSortDescriptors
- Subject: Re: Core Data, NSOutlineView and NSSortDescriptors
- From: Frank Reiff <email@hidden>
- Date: Mon, 23 Apr 2007 17:29:21 +0200
Thanks a lot, it works like a charm!
Best regards,
Frank
On 23 Apr 2007, at 16:58, Carmin Politano wrote:
In the class(s) of the data you are comparing, declare a method
which performs the comparison you want then pass that method as the
selector parameter.
example:
@implementation NSString ( myCompare )
-(NSComparisonResult) compareWithNumericSearch: (NSString *)
aString; {
return [self compare: aString options: NSNumericSearch];
}
@end
to avoid compilation error, you will have to declare (at least once)
@interface NSString ( myCompare )
-(NSComparisonResult) compareWithNumericSearch: (NSString *) aString;
@end
then...
[[NSSortDescriptor alloc] initWithKey: @"finalName" ascending: YES
selector: @seleector(compareWithNumericSearch:)]
If you want the key to be something core data cannot handle then
you must subclass NSSortDescriptor and overload
-(NSComparisonResult) compareObject: (id) aLeft toObject: (id) aRight;
The possibilities with these two things are endless sorting abilities.
...life... Carmin
On Apr 23, 2007, at 6:57 AM, Frank Reiff wrote:
Dear all,
I'm displaying the result of a core data fetch request in an
NSOutlineView and want the results sorted by default.
I have implemented a sortDescriptors member variable in my
NSWindowController that contains an array of NSSortDescriptor and
bound those to the NSTreeController's sortDescriptors binding.
I create the descriptors like this:
NSSortDescriptor* des1 = [[NSSortDescriptor alloc] initWithKey:
@"finalName" ascending: YES selector: @selector(localizedCompare:)];
NSSortDescriptor* des2 = [[NSSortDescriptor alloc] initWithKey:
@"name" ascending: YES];
sortDescriptors = [[NSArray arrayWithObjects: des1, des2, nil]
retain];
This works fine, but I want to sort numerical values correctly,
e.g. 0,1,2,3,..,9,10,11,..,19,20,21 and not the default 0, 1, 11,
12, .., 19, 2, 20, ..
This is usually achieved by using the NSNumericSearch in the mask
argument of the
- (NSComparisonResult)compare:(NSString *)aString options:
(unsigned)mask
method, but sort descriptors don't allow you to specify selector
arguments..
Is there any way of doing this anyway short of adding a category
to NSString? And would that even work with CoreData?
Any help would be appreciated.
Best regards,
Frank
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40verizon.net
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden