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

  • 關於本站
  • 免責聲明