面对NSPredicate的问题

时间:2013-06-07 11:50:51

标签: ios nsarray nspredicate

在我的项目下面是词典,我有一个词典列表,我试图根据谓词得到相同的值,但我没有得到这个值。

    NSPredicate* searchPredicate = [NSPredicate predicateWithFormat:@"(%K CONTAINS[c] %@)",@"**equipArray.equipmentName**",textField.text];

    NSLog(@"searchPredicate %@",searchPredicate);

    NSArray* searchList = [list filteredArrayUsingPredicate:searchPredicate];

但我无法获得清单。有谁可以帮助我?

    {
    equipArray =         (
                    {
            equipmentIcon = "outside.png";
            equipmentName = Outside;
        },
                    {
            equipmentIcon = "steps.png";
            equipmentName = Steps;
        },
                    {
            equipmentIcon = "partner.png";
            equipmentName = Partner;
        }
    );
    exId = 4;
    exeName = "Fireman Carry";
    exerciseAudioCue = "DG Fighting Fit-exercise_audio_test.mp3";
    exerciseDescription = "Proin gravida nibh vel velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor, nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis sed odio sit amet nibh vulputate cursus a sit amet mauris. Morbi accumsan ipsum velit. Nam nec tellus a odio tincidunt auctor a ornare odio. Sed non  mauris vitae erat consequat auctor eu in elit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Mauris in erat justo. Nullam ac urna eu felis dapibus condimentum sit amet a augue. Sed non neque elit. Sed ut imperdiet nisi. Proin condimentum fermentum nunc. Etiam pharetra, erat sed fermentum feugiat, velit mauris egestas quam, ut aliquam massa nisl quis neque. Suspendisse in orci enim.";
    exerciseType = Stamina;
    imageThumbNail = "firemancarry_thumbnail.png";
    longVideoName = long;
    shortVideoName = small;
}

4 个答案:

答案 0 :(得分:3)

如果您想查找equipmentName任何 equipArray包含的元素 给定字符串,使用:

[NSPredicate predicateWithFormat:@"ANY %K CONTAINS[c] %@", @"equipArray.equipmentName", textField.text];

(“CONTAINS”用于字符串比较,而不是检查数组中的包含。)

答案 1 :(得分:0)

使用此谓词:

[NSPredicate predicateWithFormat:@"equipArray.equipmentName =[cd] %@", textField.text];

答案 2 :(得分:0)

尝试这样,

NSPredicate* searchPredicate = [NSPredicate predicateWithFormat:@"(equipArray.equipmentName CONTAINS[c] %@)",textField.text];

答案 3 :(得分:0)

 NSPredicate *searchPredicate=[NSPredicate predicateWithFormat:@"ANY %K == [cd] %@", @"equipArray.equipmentName", @"steps"];