How do I put different types in a dictionary in the Swift Language?

You can achieve plist-like nested structures using Any type for dictionary values which is Swift’s somewhat counterpart to Objective-C’s id type but can also hold value types.

var response = Dictionary<String, Any>()
response["user"] = ["Login": "Power Ranger", "Password": "Mighty Morfin'"]
response["status"] = 200

EDIT:

Any seems to be better than AnyObject because in the above code response["status"] is of type Swift.Int, while using value type of AnyObject it is __NSCFNumber.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)