For example I have a simple block of C# codes:
IList<string> list = new List<string>();
list.Add("Objective-C");
list.Add("C#");
list.Add("C++");
list.Add("Java");
list.Add("Python");
var filteredList = list.Where(c => c.Contains("C")).ToList<string>();
The filteredList will only contain "Objective-C", "C#", and "C++".
I would like to know if Objective-C supports any method to filter the list of objects (NSArray) using lambda like this? Thanks.
NSSet
hasobjectsPassingTest:
To make the example easier, this code assumes that the set has only
NSString
objects.For
NSArrays
you can useindexesOfObjectsPassingTest:
.NSPredicates
are generally used to sort and filter through collections.These predicates are usually made with format strings instead of blocks, since these queries can handle most situations, but blocks are available as shown.
For more reading on
NSPredicates
: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Predicates/predicates.html#//apple_ref/doc/uid/TP40001789