NSPredicate 多级过滤器
NSPredicate multi level filter
I am trying to search on 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 how I will be able to search contentArray
for Customer_Name
using NSPredicate
?
尝试使用此代码
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"selectedCustomer.Customer_Name CONTAINS[c] %@", your_name_here];
NSArray *filteredArray = [contentArray filteredArrayUsingPredicate:predicate];
如果你想匹配确切的名字,可以这样尝试
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"selectedCustomer.Customer_Name LIKE '%@'", searchName];
如果你想检查名称是否包含
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"selectedCustomer.Customer_Name CONTAINS[cd] %@", searchName];
I am trying to search on 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 how I will be able to search contentArray
for Customer_Name
using NSPredicate
?
尝试使用此代码
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"selectedCustomer.Customer_Name CONTAINS[c] %@", your_name_here];
NSArray *filteredArray = [contentArray filteredArrayUsingPredicate:predicate];
如果你想匹配确切的名字,可以这样尝试
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"selectedCustomer.Customer_Name LIKE '%@'", searchName];
如果你想检查名称是否包含
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"selectedCustomer.Customer_Name CONTAINS[cd] %@", searchName];