Any methods to add-on for the dictionary inside an array? I was trying to use

[[parentArray objectAtIndex:1] addEntriesFromDictionary:newDictionary];

but I get

*** Terminating app due to uncaught exception 'NSInvalidArgumentException, 'reason: '-[__NSDictionaryI addEntriesFromDictionary:]: unrecognized selector sent to instance`
有帮助吗?

解决方案

NSDictionary is immutable, and as such, has no such selector.

You want an NSMutableDictionary, which has the addEntriesFromDictionary: selector.

Or an NSMutableArray would allow you to grab the immutable dictionary, make a new immutable dictionary from that plus your new dictionary, and then store the combined immutable dictionary back at the index the original dictionary was originally at.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top