上QQ阅读APP看书,第一时间看更新
Using generics to write generic and reusable code
Generic code is used to write reusable and flexible functionalities that can deal with any type of variables. This helps in writing reusable and clean code regardless of the type of objects your generic code deals with. An example of using generics is when you use Array and Dictionary. You can create an array of Int or String or any type you want. That's because Array is natively created and can deal with any type. Swift gives you the ability to write generic code very easily as you will see in this section.