How to combine two Dictionary instances in Swift?

前端 未结 10 1933
滥情空心
滥情空心 2020-12-01 04:13

How do I append one Dictionary to another Dictionary using Swift?

I am using the AlamoFire library to send a

10条回答
  •  感情败类
    2020-12-01 04:29

    Try This Approach

        let dict1: [String: AnyObject] = ["kFacebook": ["kToken": "token"]]
        let dict2: [String: AnyObject] = ["kRequest": ["kTargetUserId": "userId"]]
    
        var combinedAttributes : NSMutableDictionary!
    
        combinedAttributes = NSMutableDictionary(dictionary: dict1)
    
        combinedAttributes.addEntriesFromDictionary(dict2)
    
        println(combinedAttributes)
    

    It will Print Following :

    {
    kFacebook =     {
        kToken = token;
    };
    kRequest =     {
        kTargetUserId = userId;
    };
    

    }

    Hope it helps !!

提交回复
热议问题