NSArray - filteredArrayUsingPredicate:
Evaluates a given predicate against each object in the receiving array and returns a new array containing the objects for which the predicate returns true.
Declaration
SWIFT
func filteredArrayUsingPredicate(_ predicate: NSPredicate) -> [AnyObject]
OBJECTIVE-C
- (NSArray<ObjectType> *)filteredArrayUsingPredicate:(NSPredicate *)predicate
Parameters
predicate
The predicate against which to evaluate the receiving array’s elements.
Return Value
A new array containing the objects in the receiving array for which predicate returns true.
Discussion
For more details, see Predicate Programming Guide.
Availability
Available in iOS 3.0 and later.
例子:
Evaluates a given predicate against each object in the receiving array and returns a new array containing the objects for which the predicate returns true.
Declaration
SWIFT
func filteredArrayUsingPredicate(_ predicate: NSPredicate) -> [AnyObject]
OBJECTIVE-C
- (NSArray<ObjectType> *)filteredArrayUsingPredicate:(NSPredicate *)predicate
Parameters
predicate
The predicate against which to evaluate the receiving array’s elements.
Return Value
A new array containing the objects in the receiving array for which predicate returns true.
Discussion
For more details, see Predicate Programming Guide.
Availability
Available in iOS 3.0 and later.
例子:
[self.products filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"weight > 10"]];