Rss Feed
  1. Generic Stack Implementation In Swift

    Thursday, July 10, 2014

    I'm pretty excited about this new feature in Swift; Generics. This is something borrowed from C++. The `Swift Programming Language` book stated "Generic Code enables you to write flexible, reusable functions and types that can work with any type, subject to requirements you define". Basically it just means you can write functions that can work with multiple types of parameters, collection types that can perform operations on the data set without any concerns of the type of the data set.

    Below is a Gist of Generic Stack Implementation in Swift, a Stack that can work with any data types.

    In the above snippet, you can see, <T> is the additions, right next to class name, that makes it a generic type. You can make use Type T within the implementation just like any other type.

    You can check the sample project here in Github.