What are generics? How to make a method or variable generics in Swift?

What are generics? How to make a method or variable generics in Swift?

devquora

Posted On:
Feb 22, 2018

Generic is efficient to write sensitive and reusable functions and types. It is provided in Swift 4. Most of the people use this feature to evade the risk of duplication. 'Arrays' and 'Dictionary' are also referred to generic collection. The libraries of Swift 4 are comprised of generic code.

You can add generics to a method (function) but can’t add to a variable. Understand it with an example: