---
title: "How to filter array using predicate on a custom property of object in Objective- C iOS?"  
description: "How to filter array using predicate on a custom property of object in Objective- C iOS?"  
author: "Sunil Singh"  
published: 2017-01-10  
updated: 2020-09-24  
canonical: https://www.mindstick.com/interview/23158/how-to-filter-array-using-predicate-on-a-custom-property-of-object-in-objective-c-ios  
category: "ios"  
tags: ["iphone", "ios", "iphone sdk", "objective c"]  
reading_time: 1 minute  

---

# How to filter array using predicate on a custom property of object in Objective- C iOS?

Following is function that is used to filter NSArray with key and value as parameter-

```
-(NSArray*)filterArrayUsingCustomProperty:(NSArray*)arrayList
keyPath:(NSString*)key value:(NSString*)
value{NSPredicate
*predicate=[NSPredicate
predicateWithFormat:@"%K
CONTAINS [c] %@",key,value];return
[arrayList filteredArrayUsingPredicate:predicate];}
```

\

for more details of NSPredicate visit

[https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html)\

\

## Answers

### Answer by Sunil Singh

Following is function that is used to filter NSArray with key and value as parameter-

```
-(NSArray*)filterArrayUsingCustomProperty:(NSArray*)arrayList
keyPath:(NSString*)key value:(NSString*)
value{NSPredicate
*predicate=[NSPredicate
predicateWithFormat:@"%K
CONTAINS [c] %@",key,value];return
[arrayList filteredArrayUsingPredicate:predicate];}
```

\

for more details of NSPredicate visit

[https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html)\

\


---

Original Source: https://www.mindstick.com/interview/23158/how-to-filter-array-using-predicate-on-a-custom-property-of-object-in-objective-c-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
