首页 > 其他 > 详细

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

时间:2016-05-27 10:41:54      阅读:174      评论:0      收藏:0      [点我收藏+]
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))

 

技术分享

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

原文:http://www.cnblogs.com/yaoyao0110/p/5533498.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!