[swift-users] How to merge two dictionaries?
jens at mooseyard.com
Fri Nov 11 11:47:31 CST 2016
> On Nov 11, 2016, at 12:14 AM, Ray Fix via swift-users <swift-users at swift.org> wrote:
> The reason I don’t think it is provided is because it is difficult to know what to do when keys collide.
When you add a single entry to a dictionary with =, it simply replaces any existing value. I would expect adding multiple entries to do the same. (Which is what NSDictionary’s -addEntries: method does.)
Sure, there are different policies you could want, like ignoring duplicate keys or somehow combining the values, but replacing is a common default. It seems wrong not to have this method just because there’s more than one way it could work. (“Don’t let the best be the enemy of the good.”)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-users