如何在NSPredicate

时间:2015-09-09 07:43:02

标签: ios objective-c nsdictionary nspredicate

我有一个有两个数组的字典,字典是

NSDictionary * StudentDetails = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:StudentIDs,StudentNames, nil] forKeys:[NSArray arrayWithObjects:@"ID",@"NAME", nil]];

并且两个数组是

NSArray * StudentIDs = [NSArray arrayWithObjects:@"07bg1234",@"07ac1234", nil];
NSArray * StudentNames = [NSArray arrayWithObjects:@"aaaaaaa",@"bbbbb", nil];

我尝试使用谓词将数组值检索为

NSString * searchStr = @"07bg1234";

    NSPredicate * fileExtPredicate01 = [NSPredicate predicateWithFormat:@"SELF IN %@", StudentIDs];

    if (([fileExtPredicate01 evaluateWithObject: searchStr]== YES)) {
        NSLog(@"Student ID: %@ Exists",searchStr);
    }
    else {
        NSLog(@"Student ID: %@ not Exists",searchStr);
    }

到目前为止,它正常工作....当我试图将字典值作为

NSPredicate * fileExtPredicate02 = [NSPredicate predicateWithFormat:@"SELF IN %@", StudentDetails];

    if (([fileExtPredicate02 evaluateWithObject: searchStr]== YES)) {
        NSLog(@"Student Details: %@ Exists",searchStr);
    }
    else {
        NSLog(@"Student Details: %@ not Exists",searchStr);
    }

我总是得到o / p作为学生详细信息****不存在...我如何使用谓词来获取'searchStr'是否存在于词典中?提前谢谢

0 个答案:

没有答案