从嵌套的NSDictionary中删除项目的最佳方法是什么?

时间:2014-12-31 18:13:03

标签: objective-c nsmutablearray nsdictionary nsmutabledictionary

我有一系列包含NSMutableArray的NSMutableDictionaries嵌套系列。我想快速从数组中删除一个项目。

例如:

NSMutableDictionary dict包含:

{
    "foo" =     {
        "bar" =         {
            "baz" =             (
                "<MyItem: 0x17409d100>"
            );
        };
    };
}

我以为我可以通过以下方式删除它:

// MyItem *myItemToDelete = pointer to <MyItem: 0x17409d100>

NSMutableArray *tmp = [[[dict objectForKey:@"foo"] objectForKey:@"bar"] objectForKey:@"baz"];
[tmp removeObject:myItemToDelete];
currentImage = nil;

但是,执行上述操作时,tmp为nil,currentImage为nil,但原始dict仍然具有对MyItem对象的引用。

0 个答案:

没有答案