Evaluates a given predicate against each object in the receiving set and returns a new set containing the objects for which the predicate returns true.
SDKs
- iOS 3.0+
- macOS 10.5+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
func filtered(using predicate: NSPredicate) -> Set<Any Hashable>
Parameters
predicate
A predicate.
Return Value
A new set containing the objects in the receiving set for which predicate
returns true.
Discussion
The following example illustrates the use of this method.
NSSet *sourceSet =
[NSSet setWithObjects:@"One", @"Two", @"Three", @"Four", nil];
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"SELF beginswith 'T'"];
NSSet *filteredSet =
[sourceSet filteredSetUsingPredicate:predicate];
// filteredSet contains (Two, Three)