Here's what I came up with (subclass NSArrayController).

// Override to strip off the sort descriptor and sort in memory.
- (BOOL)fetchWithRequest:(NSFetchRequest*)fetchRequest merge:(BOOL)merge
        error:(NSError**)error
{
        // Copy fetch request without sort descriptor.
NSFetchRequest* strippedRequest = [[fetchRequest copyWithZone:NULL] autorelease];
        [strippedRequest setSortDescriptors:nil];
        
        // Fetch without sort descriptor.
        BOOL success = [super fetchWithRequest:strippedRequest merge:merge
                        error:error];
        
        // Sort in memory.
        // *** Not needed when bound to NSTableColumn in a table view. (?)
        //[super setSortDescriptors:[fetchRequest sortDescriptors]];
        //[super rearrangeObjects];
        
        return success;
}

Note that I did not even need the commented out code to sort in memory. The table column seems to do this for you, if that is what your array controller is bound to. However, I have only tested on Tiger and Leopard.

Cheers,
Dave

On 1-Sep-09, at 5:51 PM, Sean McBride wrote:

Melissa,

Thanks for your speedy reply.

That's great news that SnowLeopard supports those! Could you elaborate
on performance implications?  Does the SQL layer now support fancy
sorting? Or is fancy sorting done after results are retrieved from the
database?

Alas, I must support ppc so I'd still be interested to know how to
subclass NSArray/TreeController... anyone? :)

Cheers,

Sean


On 9/1/09 2:43 PM, Melissa J. Turner said:

As of SnowLeopard, Core Data supports the following selectors for
sorting in the SQLite store:

compare: (since Tiger(I think))
caseInsensitiveCompare: (since Leopard)
localizedCompare: (new in SL)
localizedCaseInsensitiveCompare: (new in SL)
localizedStandardCompare: (new in SL)

The last comparison type is new to the OS in SL, and will get you the
system standard sort as done by Finder.

As to subclassing NSArrayController, I'll leave that to people with
more UI-fu.

+Melissa


On Sep 1, 2009, at 13:10, Sean McBride wrote:

Hi all,

The "Troubleshooting Core Data" document discusses the FAQ "SQLite
store
does not work with sorting".  It suggests: "you may need to subclass
NSArrayController so you can have it not pass the sort descriptors to
the database and instead do the sorting after your data has been
fetched". [1]

I imagine this must have been done many times over by many people.
Try
as I may, I cannot find any example code, or even a more detailed
discussion of what to override.  I fear there may be edge cases
overriding such an important class, so want to be careful.

My ultimate goal is for all table and outline views in my app to sort
"correctly" (ie like the Finder[2]).

What is the correct way to achieve this?

[1] <http://developer.apple.com/mac/library/documentation/Cocoa/
Conceptual/CoreData/Articles/cdTroubleshooting.html>
[2] <http://developer.apple.com/mac/library/documentation/Cocoa/
Conceptual/Strings/Articles/SearchingStrings.html>


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/dave.fernandes%40utoronto.ca

This email sent to dave.fernan...@utoronto.ca

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to