logo
  • 教程列表
  • SO官方文档
  • 字典
    • 声明字典
    • 访问值
    • 用 Key 改变词典的价值
    • 修改词典
    • 获取字典中的所有键
    • 合并两个词典
  1. StackOverflow 文档
  2. Swift Language 教程
  3. 字典
  4. 合并两个词典

合并两个词典

Created: November-22, 2018

extension Dictionary {
    func merge(dict: Dictionary<Key,Value>) -> Dictionary<Key,Value> {
        var mutableCopy = self
        for (key, value) in dict {
            // If both dictionaries have a value for same key, the value of the other dictionary is used.
            mutableCopy[key] = value
        }
        return mutableCopy
    }
}
  • 获取字典中的所有键

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明