English 中文(简体)
从级别深处的词典中删除项目
原标题:Deleting an item from dictionary deep in the level

我有一个数组字典,其中还包含字典。我想删除最里面字典里的一个关键字。做这件事最简单、最快的方法是什么。

问题回答

只需访问内部字典,就好像它不在字典中的数组中一样。

例如:

[[[settingsDictionary objectForKey:@"key1"] objectAtIndex:index] removeObjectForKey:@"key2"];

或更分散:

NSArray *innerArray = [topDict objectForKey:@"key1"];
NSMutableDictionary *innerDict = [innerArray objectAtIndex:index];
[innerDict removeObjectForKey:@"key2"];

或者使用新的下标表示法:

[settingsDictionary[@"key1"][index] removeObjectForKey:@"key2"];

我真的没有什么特别的方法可以做到这一点,只需访问对象并调用removeObjectForKey方法。

我认为对于这个结构,没有其他方法可以获得数组的键,然后是数组中的索引和要删除的元素的键。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签