I just thought updateValue(:,:) is more natural than subscript function in Dictionary.
For example, if there is no key in the dictionary, both `dict2[key] = value` and `dict2.updateValue(value, forKey:key)` will add a new key-value pair. However, the subscript function does it by adding something on both side of the equation mark, which seems not natural to me. So I prefer to use updateValue(:,:) function instead. Besides, updateValue(:,:) function can use potential conversions before Swift 3.0, which makes it more convenient. https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160523/002021.html Zhaoxin On Tue, Aug 30, 2016 at 8:13 AM, Jens Alfke <j...@mooseyard.com> wrote: > > On Aug 29, 2016, at 4:38 PM, Zhao Xin <owe...@gmail.com> wrote: > ... > > _ = dict1.map { > > > I just use a `for` loop to iterate dict1, and inside it populate dict2. > Using `map` here seems wasteful since it’s building an array that’s thrown > away. > > dict2.updateValue(value, forKey:key) > > > This is a tangent, but: Why do you use this syntax instead of the more > readable `dict2[key] = value`? (I assume they’re equivalent internally.) > > —Jens >
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users