Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Soccer League Coordinator in Swift

Project 1 - Unable to create an array of dictionaries

Hi, I am working on project 1 and I am stuck when creating an array of dictionaries to hold all of my player information. My thought process is as follows:

1) Create an array to hold all player names. Create a seperate dictionary to hold player height, player experience, and player guardian information. 2) Create an array to hold the player height, player experience, and player guardian dictionaries.

I am stuck when typing the following line of code:

let playerInformation = [playerName, playerHeight, playerExperience, playerGuardian]

I receive a "Type of expression is ambiguous without more context"

I'm assuming I have to tell the array what types my dictionaries are, but I can't seem to figure this part out.

NOTE: I also tried creating a single dictionary to hold the player info as follows:

let playerOne: [String: AnyObject] = ["name": "Arnold Willis", "height": "43", "hasExperience": "false", "guardianName": "Claire Willis"]

This resulted in a "value of type string does not conform to any object" error.

3 Answers

Stone Preston
Stone Preston
42,016 Points

I think it wants a dictionary for the player info for each player, then an array that holds those dictionaries of multiple players. You can use [String: String] as the dict type since all your data are Strings

let playerOne: [String: String] = ["name": "Arnold Willis", "height": "43", "hasExperience": "false", "guardianName": "Claire Willis"]

and then when you have multiple players

let playerInformation: [[String: String]]  = [playerOne, playerTwo, playerThree]
Damian Nelson
Damian Nelson
11,202 Points

Importing foundation at the beginning of my code took care of that particular issue for me.

Thank you both! That helped me get past step 1.