有沒有辦法使用索引訪問Swift 2中的字典鍵?如何通過索引訪問字典鍵?
var dict = ["item1":1, "item2":2, "item3":3]
dict.keys[0]
導致錯誤:
15:29: note: overloads for 'subscript' exist with these partially matching parameter lists: (Base.Index), (Range), (Self.Index) print("key=" + dict.keys[i])
只見從八月(Swift: dictionary access via index)這樣一個例子:
dict.keys.array[0]
至少在夫特2中,不是數組字典鍵上的對象。