Syed Ismail Ahamed Syed Ismail Ahamed - 3 months ago 14
iOS Question

NSPredicate multi level filter

I am trying to search an

NSMutableArray
with two levels drill down with custom objects, I tried using
SELF
and
ANY
but no luck.

I have an
NSMutableArray
say
contentArray

Content Array

contentArray
{
OBJECTA,
OBJECTA
}


Which has custom objects (
OBJECTA
),
objectA
in turn has a custom object called
Customer


OBJECTA:

@interface OBJECTA : NSObject
{
@property (strong,nonatomic) Customer * selectedCustomer;

}
@end


CUSTOMER:

@interface Customer : NSObject

@property(strong,nonatomic) NSString* Customer_Name;

@end


Now will I be able to search
contentArray
for
Customer_Name
using
NSPredicate
?

Answer

Try like this way if you want to match exact name

NSPrdicate *prdicate = [NSPredicate predicateWithFormat:@"selectedCustomer.Customer_Name LIKE '%@'", searhcName];

If you want to check name contains than

NSPrdicate *prdicate = [NSPredicate predicateWithFormat:@"selectedCustomer.Customer_Name CONTAINS[cd] %@", searhcName];
Comments