• 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
Re: NSTableView searching and predicates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView searching and predicates


  • Subject: Re: NSTableView searching and predicates
  • From: mmalc crawford <email@hidden>
  • Date: Fri, 3 Aug 2007 07:20:38 -0700


On Aug 3, 2007, at 6:49 AM, Daniel Wambold wrote:

-(void) myEventSearch:(id)sender
{
NSString *mySearchString;
if ([sender stringValue] == nil)
{
mySearchString = [[[NSString alloc] initWithString:@""] autorelease];
}
else
{
mySearchString = [[[NSString alloc] initWithString:[sender stringValue]] autorelease];
}


NSPredicate *myFilterPredicate = [[[NSPredicate alloc] init] autorelease];
myFilterPredicate = [NSPredicate predicateWithFormat:@"%@ IN[cd] myEvent || %@ IN[cd] myNotes", mySearchString, mySearchString];
[self setFilterPredicate:myFilterPredicate];
[self rearrangeObjects];
}


It's not clear why you're making this code so verbose, and why you're creating objects unnecessarily.

	mySearchString = [[[NSString alloc] initWithString:@""] autorelease];
could simply be
	mySearchString = @"";


mySearchString = [[[NSString alloc] initWithString:[sender stringValue]] autorelease];
could simply be
mySearchString = [NSString stringWithString:[sender stringValue]];
although it's not necessary to copy this anyway.


NSPredicate *myFilterPredicate = [[[NSPredicate alloc] init] autorelease];
You just throw this object away...



The whole method could be reduced to:


-(void) myEventSearch:(id)sender
{
NSPredicate *myFilterPredicate;
NSString *mySearchString = [sender stringValue];
if (mySearchString != nil)
{
myFilterPredicate = [NSPredicate predicateWithFormat:
@"%@ IN[cd] myEvent || %@ IN[cd] myNotes", mySearchString, mySearchString];
}
[self setFilterPredicate:myFilterPredicate];
[self rearrangeObjects];
}




Listening for NSTableViewSelectionDidChangeNotifications and logging the selectionIndex shows occasional erratic behavior, with the value returning out of order occasionally or even as a very large integer like 2147483647. Apparently, the underlying collection of objects is not properly rearranged in, perhaps, the implementation of NSTableView, but somewhere, the program is running into a problem with this implementation. Below is the GDB call stack (is that what this is called?) at the crash.

The problem, then, almost certainly lies elsewhere.

It's not immediately clear from your earlier message my you're executing a fetch in - (NSArray *)arrangeObjects:(NSArray *)objects rather than simply arranging the objects you're passed. If you end up returning more objects than you were passed in, I could imagine that would cause problems...

mmalc





_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSTableView searching and predicates
      • From: Andrew Farmer <email@hidden>
References: 
 >NSTableView searching and predicates (From: Daniel Wambold <email@hidden>)

  • Prev by Date: NSTableView searching and predicates
  • Next by Date: Outline view and expanding most recent item
  • Previous by thread: NSTableView searching and predicates
  • Next by thread: Re: NSTableView searching and predicates
  • Index(es):
    • Date
    • Thread