There comes a time when you have to create an Array of objects which are of different types. A generic solution to this problem is to create an
Why do you need it?
Whenever there comes a need to create an array of anyobject, just consider redesigning the code instead. Why would you create a list of heterogenous type in the first place?
But if the list is somewhat similar then you can use Protocol oriented Programming for this.
Protocol Oriented Solution
Swift is focusing more on protocol oriented programming. So if you have to create an array of similar but not the same data types, then you can make all the similar types conform to a
Protocol and create an array of the Protocol.
Here is the example