• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Array Controller sort descriptors vs. SQLite data store (was Re: localized compare and SQLite persistent store)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Array Controller sort descriptors vs. SQLite data store (was Re: localized compare and SQLite persistent store)


  • Subject: Array Controller sort descriptors vs. SQLite data store (was Re: localized compare and SQLite persistent store)
  • From: Jim Correia <email@hidden>
  • Date: Wed, 7 Sep 2005 11:35:25 -0400

On Aug 11, 2005, at 4:20 PM, Melissa Turner wrote:

Short answer:

Because the SQL store doesn't know anything about localizedCaseInsensitiveCompare:

Longer explanation:

When your array controller pulls its contents from the database, it does so using an NSFetchRequest with the entity you are requesting, any predicate you have set to specify which instances of that entity you want, and any sort descriptors you have set to describe how the data should be brought back.

In the XML, binary and in memory stores, the evaluation of the predicate and sort descriptors happens in memory, where we have full access to the obj-C runtime, Cocoa, and all the goodness therein, including the comparison methods on NSString.

The SQL store on the other hand, compiles the predicate and sort descriptors to SQL, and evaluates the result in the database itself. This is done primarily for speed; databases are much faster at this, it's what they're designed for. But it means that evaluation is happening in a non-Cocoa world, and so sort descriptors (or predicates) which rely on Cocoa simply can't work, and result in exceptions like the one you're seeing.

You may need to subclass NSArrayController so you can have it not pass the sort descriptors to the database and do the sorting after your data has been fetched instead.

Do you have an example?

Or recommendations for a more general solution?

Is it a simple matter of overriding - (BOOL)fetchWithRequest: (NSFetchRequest *)fetchRequest merge:(BOOL)merge error:(NSError **) error; ?

I've been using the XML store since the documentation recommends it for debugging, but just switched over to the SQLite store (which I intend to ship with) to see what the fallout was. That the sort descriptors are applied in the database and not afterwards generates problems for me in a few places right off the bat:

1) an NSTableView which was using localizedCaseInsensitiveCompare: for the columns

2) derived attributes

I have a "source list" for which I've manually set the sort descriptors based on name and priority. Priority isn't a model attribute, but a constant returned from a KVC compliant method based on the object type.

Upon loading the UI, the controller fetches and logs

2005-09-07 11:28:08.782 Organizer[1820] *** NSRunLoop ignoring exception 'unresolved keypath: priority' that raised during posting of delayed perform with target 4c2b20 and selector 'invokeWithTarget:'


Was this problem previously considered? Proposed solution?

Thanks,
Jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Array Controller sort descriptors vs. SQLite data store (was Re: localized compare and SQLite persistent store)
      • From: Jim Correia <email@hidden>
  • Prev by Date: IBOutlet not 'sticking' at runtime
  • Next by Date: IB - HowTo put an NSButtonCell in TableColumn
  • Previous by thread: Re: IBOutlet not 'sticking' at runtime
  • Next by thread: Re: Array Controller sort descriptors vs. SQLite data store (was Re: localized compare and SQLite persistent store)
  • Index(es):
    • Date
    • Thread