Mohsin Qureshi
Mohsin Qureshi

Reputation: 1213

Generic Type Aliases in Swift 3?

How can we declare Generic Type Aliases in swift 3.

I tried following :

typealias DictionaryOfStrings<T>  = Dictionary<T, String>

And producing error:

error: type 'T' does not conform to protocol 'Hashable'

Upvotes: 1

Views: 1036

Answers (1)

Wilson
Wilson

Reputation: 9136

typealias DictionaryOfStrings<T: Hashable> = Dictionary<T, String>

var dict = DictionaryOfStrings<Int>()

dict[1] = "One"
dict[2] = "Two"

Upvotes: 2

Related Questions