0

我有带有字典的 nsarray,但我正在获取数组中的元素。如果我运行这一行:

po [ myArray valueForKeyPath:@"today"]

我得到这个输出:

<null>,
<null>,
<null>,
{
    sales = @"1";
    typeOfSale = @"onLine";
}
)

我试试这个:

[myArray removeObjectIdenticalTo:[NSNull null]];

但没有用。

你们中的任何人都知道我可以删除吗?

4

2 回答 2

1

您不能删除相同的 NSNull 对象,因为您的数组不包含 NSNull。它包含类似 NSDictionary 的东西,它没有 @"today" 的值。

最简单的解决方案是执行以下操作:

[myArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"today != nil"]];
于 2013-07-15T23:41:50.717 回答
0

我用以下行解决了这个问题:

[myArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"%K != %@", key, nil]];

于 2013-07-16T01:03:27.640 回答