Swift - Multiple Type Parameters

Introduction

You can define functions to accept arguments of multiple data types.

To define a function that deals with Dictionary types, you have to deal with key-value pairs, as shown in the following function:

func addToDictionary(key:Int, value:String) {
...
}

Here, you have two parameters: one of type Int and one of type String.

The generic version of this function would look like this:

func addToDictionary<KeyType , ValueType > (key:KeyType , value:ValueType ){
...
}

Here, the KeyType and ValueType are placeholders for the actual data type that you will use.

Related Topic