RickardTF
RickardTF

Reputation: 33

Swift array of dictionary append

I have scoured any and all resources i can find, but i can't figure this out. Feels like it should be simple.

I have created an Array of Dictionaries for a NSTableView. I want to append it for a reload. A simple example of what I'm trying to do:

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

I can do this using Int only with ease. I have tried to declare it as an Array, NSMutableArray and tried to declare the dictionary : [Dictionary] = []. With a lot of experimenting i ran into a lot of NSObject errors. Maybe this is not proper? Im new to Swift and may be missing something - any help would be great. Thanks,

Upvotes: 0

Views: 128

Answers (2)

user5034511
user5034511

Reputation:

You should be good if you change the last line to:

allPlayers.append(oneMorePlayer)

Upvotes: 0

Drewster
Drewster

Reputation: 539

You have the name of your allPlayers array wrong.

allPlayers.append(oneMorePlayer) 

Upvotes: 1

Related Questions