2016-06-22 187 views
-2

如何將Dictionary<String, String>添加到`Array>?如何將Dictionary <String,String>添加到Array <Dictionary <String,String >>?

我嘗試這樣做:

self.playerData.basicItemDict += self.playerData.selectedItemArray

我試圖尋找在堆棧上的答案,但不可能令人驚訝的發現任何東西。

謝謝!

+2

參見[文檔'+ ='](https://developer.apple.com/reference/swift/1779117),其是如['追加(contentsOf:)']( https://developer.apple.com/reference/swift/array/1690087-append)。它可以讓你做一些事情,比如'[1,2] + = [3,4]來獲得[1,2,3,4]'。將它與[Array.append(_:)']的文檔(https://developer.apple.com/reference/swift/array/1538872-append)相比較,後者附加了特定的元素,例如'[1 ,2] .append(3)得到[1,2,3]' – Alexander

回答

4

你應該嘗試append方法。像這樣:

array.append(dictionary) 
+0

你的天才!非常感謝! – brkr

+0

@brkr如果它對你有幫助,請將此答案標記爲正確! :) – Ike10

相關問題