各要素がNSDictionary
である配列があります。
NSMutableArray *mutArr = [NSMutableArray array];
for (Person *person in persons) {
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:person.name, @"name", person.email, @"email", nil];
[mutArr addObject:dict];
}
self.arr = [[NSArray alloc] initWithArray:mutArr];
名前または電子メールでarr
をファイラー化する方法には、@"filter string"
メソッドを使用して文字列filterArrayUsingPredicate:
が含まれます。
前もって感謝します!
以下の例をご覧ください。
NSArray *array = [NSArray arrayWithObject:[NSMutableDictionary dictionaryWithObject:@"filter string" forKey:@"email"]]; // you can also do same for Name key...
NSArray *filteredarray = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(email == %@)", @"filter string"]];
これをチェックしてください:
var customerNameDict = ["firstName":"karthi","LastName":"alagu","MiddleName":"prabhu"];
var clientNameDict = ["firstName":"Selva","LastName":"kumar","MiddleName":"m"];
var employeeNameDict = ["firstName":"karthi","LastName":"prabhu","MiddleName":"kp"];
var attributeValue = "karthi";
var arrNames:Array = [customerNameDict,clientNameDict,employeeNameDict];
var namePredicate = NSPredicate(format: "firstName like %@",attributeValue);
let filteredArray = arrNames.filter { namePredicate.evaluateWithObject($0) };
println("names = ,\(filteredArray)");