13.范型函数的使用:将字典合并到当前字典

extension Dictionary {
    /// 将字典合并到当前字典
    //字典的分类法, 如果要使用 updateValue 需要明确的指定类型,范型函数
    
    mutating func merge<K, V>(dict: [K: V]) {
        for (k, v) in dict {
            self.updateValue(v as! Value, forKey: k as! Key)
        }
//
updateValue

    /// Update the value stored in the dictionary for the given key, or, if the


    /// key does not exist, add a new key-value pair to the dictionary.


    ///


    /// Returns the value that was replaced, or `nil` if a new key-value pair


    /// was added.


    }

//取出并且拼接 currentCls 的模型字典


      使用 : infoDict.merge(modelInfo(currentCls))

 

posted @ 2016-05-27 09:37  妖妖yaoyao  阅读(117)  评论(0编辑  收藏  举报