2012-04-16 110 views
0

我需要过滤下列数组,状态等于“U”我已经使用了以下内容。使用谓词过滤器阵列

NSArray *result = [alertModified.senders filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(subscriptions.status = %@)",@"U"]]; 

但我得到空阵列。

请帮我过滤吗?

阵列字符串:

(senderCode = CPFB, senderName = CPFB, forSenderLevel = 0, subscriptions = (
"correspondenceListId = 102,status = S,senderCode = AA,subject = Letter,retentionPeriod = 0, uniqueBillIdentifier = (null),senderResponseStatus = (null),subscriptionDate = ,effectiveDate = ", 
"correspondenceListId = 103,status = U,senderCode = BB,subject = Nomination Letters,retentionPeriod = 0, uniqueBillIdentifier = (null),senderResponseStatus = (null),subscriptionDate = ,effectiveDate = ", 
"correspondenceListId = 104,status = U,senderCode = AA,subject = Yearly statements,retentionPeriod = 0, uniqueBillIdentifier = (null),senderResponseStatus = (null),subscriptionDate = ,effectiveDate = ", 
"correspondenceListId = 105,status = U,senderCode = BB,subject = All Future Letters,retentionPeriod = 0, uniqueBillIdentifier = (null),senderResponseStatus = (null),subscriptionDate = ,effectiveDate = ")) 
+0

所以,你需要排序**订阅**,或整个字符串? – 2012-04-16 11:34:32

+0

这是一个由逗号分隔的字符串组成的数组吗? – wbyoung 2012-04-16 12:17:09

+0

我不需要排序,但我需要筛选出状态为“U”的记录,即我应该从上面只取得3条记录。上面的字符串是对象层次的表示。 – lasi 2012-04-16 13:06:31

回答

0

在你的榜样,你应该过滤订阅列表本身,而不是整个发件人。您必须将过滤器应用于每个发件人。尝试改变你的过滤器线,并检查它是否给你结果:

NSArray *result = [[alertModified.senders objectAtIndex:0].subscriptions filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(status = %@)",@"U"]]; 
+0

谢谢天使。但我想迭代嵌套数组,而不是在一个数组中。您的代码片段过滤器在单个列表中。 – lasi 2012-04-16 15:15:07