O'Reilly logo

Application Development with Swift by Hossam Ghareeb

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generics

The generic code is used to write usable and flexible functionalities that can deal with any type. This helps you avoid duplication and write code that is very clean and easy to edit and debug. Examples of using generics are 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 generic and can deal with any type. Swift gives you the ability to write generic code very easily, as you will see in the following example. In the example, we will explain how to use Stack data structure. Stack is commonly used in algorithms and data structures. You can notice the use of stack in UINavigationController, as the view controllers are inserted in a stack, and you can easily push or ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required