2011-02-14 53 views
2

我期待在以下类型的数据结构:NSPredicate与子阵列

 
{ 
    author = "Author 1"; 
    channelIds =   (
     7 
    ); 
}, 
{ 
    author = "Author 2"; 
    channelIds =   (
     7, 
     1 
    ); 
}, 
, 
{ 
    author = "Author 3"; 
    channelIds =   (
     3, 
     7 
    ); 
} 

我想建立一个由所有项的阵列,其中channeldIds = 7

我正沿着以下谓词的行尝试新事物:

NSPredicate * filterById = [NSPredicate predicateWithFormat:@"channelIds[0] = '7'"]; 
  • 我怎样才能做到想什么,我在这里?
  • 我可以有x个channelIds,有什么方法可以迭代谓词吗?

蒂亚,S.

回答

2

更容易:

NSPredicate *filterById = [NSPredicate predicateWithFormat:@"channelIds CONTAINS %@", @"7"]; 

这是假设你的channelIds值是的阵列。如果它是一组数字(NSNumber),那么您的格式字符串将简单地为@"channelIds CONTAINS 7"