Reputation: 1213
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
Reputation: 9136
typealias DictionaryOfStrings<T: Hashable> = Dictionary<T, String>
var dict = DictionaryOfStrings<Int>()
dict[1] = "One"
dict[2] = "Two"
Upvotes: 2