2016-09-21 102 views
0

我們如何可以聲明泛型類型別名在迅速3.Swift 3中的泛型類別別名?

我嘗試以下操作:

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

而產生錯誤:

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

+1

'typealias DictionaryOfStrings =字典'我猜。請嘗試讓我們知道。 – Moritz

+0

@EricAya好的我會記住的。 –

+0

@Mohsin typealias DictionaryOfStrings = Dictionary pl。嘗試這個 –

回答

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

var dict = DictionaryOfStrings<Int>() 

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