view raw
Zonily Jame Zonily Jame - 6 months ago 51
Swift Question

Append values to [String : AnyObject] or [String : String]

I want to append values to a variable of type

[String : AnyObject]
how do I do that? cause I can't do the ff.

var someObject:[String : AnyObject] = ["name":"John Diggle", "location":"Star City Prison"]

someObject.append(["work":"soldier"]) // does not work (by that I mean there is no .append function like that of other collection types such as NSMutableArray and NSMutableDictionary
someObject = someObject + ["work":"soldier"] // does not work

I'm finding a way to make easier parameters for Alamofire since Alamofire.request uses
[String : AnyObject]


You cannot append into a dictionary. Simply add new value under a new key like that:

object["Work"] = "Soldier"

Then new value added into the dictionary.