Swift数组字典附加

时间:2015-08-17 06:13:20

标签: arrays macos swift dictionary

我已经搜索了我能找到的任何和所有资源,但我无法弄清楚这一点。感觉它应该很简单。

我为NSTableView创建了一个字典数组。我想将它附加到重新加载。 我正在尝试做的一个简单例子:

var player1 = ["PlayerName": "Rob", "name": "BugDestroyer", "campaign": "Thugs Life"]
var player2 = ["PlayerName": "Tom", "name": "Conan", "campaign": "Thugs Life"]
var player3 = ["PlayerName": "Hank", "name": "Kaldat", "campaign": "Thugs Life"]
var player4 = ["PlayerName": "Marry", "name": "Claudia", "campaign": "Thugs Life"]
var allPlayers = [player1, player2, player3, player4]
var oneMorePlayer = ["PlayerName": "Conrad", "name": "The Joker", "campaign": "Thugs Life"]
allplayer.append(oneMorePlayer) // this is where it fails - can not append and i can not find an option or another solution

我可以轻松地使用Int来做到这一点。我试图将它声明为一个数组,NSMutableArray并试图声明字典:[Dictionary] = []。经过大量的实验,我遇到了很多NSObject错误。 也许这不合适?我是Swift的新手,可能会遗漏一些东西 - 任何帮助都会很棒。谢谢,

2 个答案:

答案 0 :(得分:1)

你的allPlayers数组名称错误。

allPlayers.append(oneMorePlayer) 

答案 1 :(得分:0)

如果将最后一行更改为:

,那么你应该很好

allPlayers.append(oneMorePlayer)