2012-12-21 15 views
0
NSArray *details = [NSArray arrayWithObjects:@"name",@"age",@"gender",nil]; 
NSArray *ray1 = @[@"ray",@"23",@"male"]; 
NSArray *steve1 = @[@"steve",@"23",@"male"]; 
NSDictionary *ray = [NSDictionary dictionaryWithObjects:ray1 forKeys:details]; 
NSDictionary *steve = [NSDictionary dictionaryWithObjects:steve1 forKeys:details]; 
NSArray *register = @[ray,steve]; 

我需要過濾僅使用NSPredicate如何從使用NSPredicate

+0

首先,你不能使用'register'作爲變量名,它是一個關鍵字!!! –

+0

你能解釋一下你想要的嗎?只有數組中沒有鍵的值?就像{ray,23,male}。或者你想讓謂詞像objectForKey一樣工作:? –

+0

謝謝你的迴應Anoop Vaidya ....我找到了答案。 – ray1th

回答

1

此打印所有的字典的鍵「name」的值的密鑰的值的字典的陣列僅過濾特定鍵值

NSArray *details = [NSArray arrayWithObjects:@"name",@"age",@"gender",nil]; 
NSArray *ray1 = @[@"ray",@"23",@"male"]; 
NSArray *steve1 = @[@"steve",@"23",@"male"]; 
NSDictionary *ray = [NSDictionary dictionaryWithObjects:ray1 forKeys:details]; 
NSDictionary *steve = [NSDictionary dictionaryWithObjects:steve1 forKeys:details]; 
NSArray *reg = @[ray,steve]; 
NSPredicate *pr = [NSPredicate predicateWithValue:YES]; 
NSArray *ar = [[reg valueForKey:@"name"] filteredArrayUsingPredicate:pr]; 
NSLog(@"%@",ar);