discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Filter array using NSPredicate


From: Koh Nyap-Hong
Subject: Filter array using NSPredicate
Date: Sun, 3 Oct 2010 21:29:01 +0800

Hi List,

I with to filter array using NSPredicate (seems a lot more easier than  while loop with NSEnumerator), after read through some cocoa examples online, I run a simple test using the following codes:

 NSArray *pitches = [NSArray arrayWithObjects: @"Do", @"Re", @"Mi", @"Fa", @"So", @"La", nil];

  NSArray *filteredWithSELF = [pitches filteredArrayUsingPredicate: [NSPredicate predicateWithFormat: @"SELF == 'Do'"]]; 
  NSArray *filteredWithDescription = [pitches filteredArrayUsingPredicate: [NSPredicate predicateWithFormat: @"description == 'Do'"]];
  NSArray *filteredWithFormat = [pitches filteredArrayUsingPredicate: [NSPredicate predicateWithFormat: @"SELF == '%@'", @"Do"]];

Out of the three predicate statements, however,  the first and last one return me empty array. Only the second one returns an array containing 1 element which is the @"Do" string.

Did I make any mistake in the codes, or this feature is not fully implemented yet in base-1.20? 

Thanks and Regards,
Nyap-Hong

reply via email to

[Prev in Thread] Current Thread [Next in Thread]