• 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
Strange bug (?) with NSArrayController sortDescriptors and SQLite !
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange bug (?) with NSArrayController sortDescriptors and SQLite !


  • Subject: Strange bug (?) with NSArrayController sortDescriptors and SQLite !
  • From: Eric Morand <email@hidden>
  • Date: Tue, 6 Sep 2005 23:17:13 +0200

Hi list !



I don't know for sure if what I found is a bug or a limitation of SQLite store I'm not aware of, but I have to share it with you.

Here is a link to a simple Xcode project (named CoreDataTest) :


http://homepage.mac.com/eric.morand/.Pictures/CoreDataTest.xcodeproj.zip


It has been created using the Core Data Application template of Xcode. What has been added are :


- In the model : an Entity named MyEntity, of class MyClass, with one attribute : a string named "name"

- In CoreDataTestAppDelegate : the following method :

- (NSArray *)sortDescriptors
{
NSSortDescriptor * sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"customName" ascending:YES] autorelease];


    return [NSArray arrayWithObject:sortDescriptor];
}

- In MyClass.m : the following method :

- (NSString *)customName
{
    return @"customName";
}



The MainMenu.nib has been populated alt-dragging the MyEntity entity and choosing 'Many objects'. In the nib, I wanted the NSArrayController to use the sort descriptors added in the app delegate (see method above) so I set its sortDescriptors binding to the sortDescriptors methos of the app delegate.

I think, that's all. As you can see, what I wanted to do was to have the array controller sorted on the property "customName".




Well, now, play with the app (add some objects, quit, then launch the app again) and see that...it works perfectly ! :o)






Well, now, change the persistor type to SQL in the app delegate. For your convenience, search for this in CoreDataTestAppDelegate :


// Comment the following line...
url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @"CoreDataTest.xml"]];
// ...and uncomment this one to witness a strange bug (?)
//url = [NSURL fileURLWithPath: [applicationSupportFolder stringByAppendingPathComponent: @"CoreDataTest.sql"]];



and

// Comment the following line...
if ([coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:nil error:&error])
// ...and uncomment this one to witness a strange bug (?)
//if ([coordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:nil error:&error])


And comment/uncomment the lines according to the explanation.



Now, compile and test the app !

If everything happens like on my computer, you should have the following message in the console :

*** NSRunLoop ignoring exception 'unresolved keypath: customName' that raised during posting of delayed perform with target 391d90 and selector 'invokeWithTarget:'



Anyway, try to add some objects. Evrything seems to work fine. Quit the app (using option-Q) and launch it again : the objects created previously are missing !

Of course, changin the sortDescriptors method of the app delegate to this :

- (NSArray *)sortDescriptors
{
NSSortDescriptor * sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES] autorelease];


    return [NSArray arrayWithObject:sortDescriptor];
}



...solves the problem and the objects are back ! Put it back to :

- (NSArray *)sortDescriptors
{
NSSortDescriptor * sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"customName" ascending:YES] autorelease];


    return [NSArray arrayWithObject:sortDescriptor];
}

...and the error message appears and the objects are missing !





What's wrong here ? The problem only happens with SQL store and doesn't allow an NSArrayController to be sorted on a derived value ! And in particular, it prevents an array controller to be sorted on a localized value derived from a property !






Did I miss something with SQLite persistent store ? Or is it a bug ?





Thanks for your help,


Eric.

_______________________________________________
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: Strange bug (?) with NSArrayController sortDescriptors and SQLite !
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Re: NSKeyedArchiver - better ways to autosave documents?
  • Next by Date: nstimer not firing?
  • Previous by thread: Padding around a borderless NSTextField
  • Next by thread: Re: Strange bug (?) with NSArrayController sortDescriptors and SQLite !
  • Index(es):
    • Date
    • Thread