0

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,

2
  • I do see that typo. and the example above does work when fixed. Commented Aug 17, 2015 at 7:14
  • But, now i notice that the issue in my project also has to do with my var allplayers declared empty. The array has to have content before it can be appended. Commented Aug 17, 2015 at 7:36

2 Answers 2

1

You have the name of your allPlayers array wrong.

allPlayers.append(oneMorePlayer) 
Sign up to request clarification or add additional context in comments.

2 Comments

ah! that was it - a typo. Back in my project i see its still is not working - but i think that is more to do with the database I'm pulling from. Now that i know this does work, i can work back from there parsing it. Thanks for the extra pair of eyes!
I wish I had a dollar for the number of times I've been stumped by similar!
0

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

allPlayers.append(oneMorePlayer)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.