Generics are type safe, meaning if you pass a string as a generic and try to use as a integer the compiler will complain and you will not be able to compile your (which is good). (This happens because Swift is using Static typing, and is able to give you a compiler error)
If you use AnyObject the compiler has no idea if the object can be treated as a String or as an Integer. It will allow you to do whatever you want with it (which is bad).
e.g. if you try to pass a String when it the your previously used Integer the application will crash. (This happens because Swift is using Dynamic typing and will only give you a runtime crash)
Generics basically tells the compiler:
“I am going to give you a type later and I want you to enforce that
type everywhere I specify.”
AnyObject basically tells the compiler:
“Don’t worry about this variable no need to enforce any type here let me do whatever I want to.”