I usually use [String: AnyObject]
. But I noticed that Alamofire uses [String: Any]
. I read somewhere that Any
is "superior" than AnyObject
or "encompasses" AnyObject
. But other than that, I don't know if there's any different between them. Is there any downside in the long run if I define dictionary as [String: Any]
instead of [String: AnyObject]
? Thanks.
Any allowed use to work with a mix of different types including function and non-class types such as Int, String, and Bool. According to the documentation, the elements in this array are Structs that are value types, so in theory
AnyObject shouldn’t work in these cases.
we would use AnyObject for Class types because they are a little more specific than Any. But again, the use of AnyObject is just an option.
more explaination you can find here. I hope all your doubts will clear after go through this link
https://medium.com/@mimicatcodes/any-vs-anyobject-in-swift-3-b1a8d3a02e00