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

HELP iOS Techdegree Students!

Hello. I am on the iOS Development Techdegree and I am a little confused on the first project, Soccer Coordinator. The instructions say create logic to iterate and assign the players to teams, and the amount of experienced players on each team need to be the same. This sounds overly complicating and may be things we haven't covered like randomly assigning a player to a team while maintaining the experienced players. Maybe I'm over thinking it. Do you manually assign the players to the teams? I am completely lost, and I don't even know where to start. Thank you.

7 Answers

Hey Bill!

This was a very difficult start for me but when i saw another way to do this it started to click maybe you just need to see how someone else did it in order to understand. And it does sound overly complicated but hopefully this will help a little i would start with theory code and an outline of what you need to make this work. my outline looks like this...

//Table Of Contents
    //Defining Player Experience
    //The dictionary index for players
    //The dictionary for players
    //Building Containers to Orginizing Experienced & Inexperienced Players
    //Defining Range & Experience of height to sort the players(#Extra Credit!)
    //Soccor Teams
    //Finding the Avareage Team's & Experienced Players
    //Placing Experineced Players
    //Welcome Letters to the Parent Guardians

my 3 hints to you are this: 
tip1#
logic used may start by looking something like this:

//empty dictionaries ready to make logic or rather (some kind of loop to channel your player into)
var experiencedPlayers: [[String: AnyObject]] = []
var unexperiencedPlayers: [[String: AnyObject]] = []
tip#2
//index for player dictionary
let joeSmith: [String : AnyObject] =
    ["Name":"Joe Smith", "Experience": true, "Parent Guardian": "Mr. & Mrs. Smith"]
let jillTanner:[String : AnyObject] =
    ["Name" : "Jill Tanner","Experience": true, "Parent Guardian": "Clara Tanner"]

//then the actual dictionary
let playerRoster =
    [joeSmith, jillTanner]

//make empty dictionaries for your teams.... you should be able to do that

tip#3

one of the last few things i had a lot of trouble with was this:

//logic(loop) for exp none exp players

for player in playerRoster {
    if player["Experience"] as! Bool == true {
        //put player in the experienced dictionary
    } else {
        //put player in the noneexperienced dictionary
    }
}


//
for playersWithExperience in experiencedPlayers {
    if numberOfExperiencedPlayer > teamDragons.count {
        teamDragons.append(playersWithExperience)
    } else if numberOfExperiencedPlayer > teamSharks.count {
        teamSharks.append(playersWithExperience)
    } else if numberOfExperiencedPlayer > teamRaptors.count {
        teamRaptors.append(playersWithExperience)
    }
}

for playersWithoutExperience in unexperiencedPlayers {
    if averageTeamsPlayers > teamDragons.count {
        teamDragons.append(playersWithoutExperience)
    } else if  averageTeamsPlayers > teamSharks.count {
        teamSharks.append(playersWithoutExperience)
    } else if averageTeamsPlayers > teamRaptors.count {
        teamRaptors.append(playersWithoutExperience)
    }
}

//ofcourse after that you need to make loops to send parent letters using interpolation and the print method

Let me know if this helps a little... (anyone). =) good luck

Thanks Harold. I am a little lost on the last tip, but I will figure it out on my own. I don't want to copy your code. I want to be sure I do the project. I appreciate the help.

Jo Lingenfelter,

This is what I ended up with. After I created an array of dictionaries for the entire team I assigned them to a seperate array based on skill levels: while index < numberOfPlayers { if soccerLeague[index]["experience"] == "YES" { experiencedPlayers.append(soccerLeague[index]["name"]!) experiencedPlayersParents.append(soccerLeague[index]["parents"]!) index+=1 } then I had an else that filled in the rest.

Next I had another while loop with an if statement (very much like the one above) that filled in the teams.
It works... but I feel there are many ways to do this.

Thanks for writing back! I did it differently and was just curious about other peoples' logic. I wrote a method to sort the players into groups based on experience and then put them into teams by using the modulus operator on their index values (index % 3).

Bill,

I think the point is to create logic to assign the players to a team. So, (this probably isn't exactly what they want, just an idea), once you have your array or dictionary, you could use an if statement followed by a while loop or vice versa. while index < totalPlayers { if playersExperience[index] = "NO" { if teamDragons.count < 3 {

.... you get the idea. The above probably isn't the correct way to handle it, as they mention something about "not assigning arrays to individual attributes" or something like that, but it gives you an idea of the possible logic needed. Hope this helps.

Could you be a little more explicit about your logic??

Don't worry bill this is no where near my code so i gave this to you in a way that it my trigger some thoughts cause that how i wanted to find out to i would not spoil it for you but I'm glad it helped even a little bit man good luck!

Just one more question. What is the averageTeamsPlayers?

seriously that took me days and i was mad when i found out how simple it was its basically like this...

averageTeamsPlayers = the roster count /  the soccer teams count

//make the soccer team count by putting them together like:

soccerTeams = dragon, sharks, raptors

then you can have soccer teams.count

Jo,

that's pretty sweet, I would not have thought to use the modulus operator. Nice...

Your response was interesting to me as well! I was having trouble working through the logic of that loop and felt like using the modulus operator was a bit of a cop-out.

Jo, have you finished the quiz app project yet?

Ciao! Not yet. Working through it slowly in addition to a project that I'm working on for another iOS program. Are you stuck on/struggling with something?

No, just finished it up. I was just curious to see how you set some of your logic in there.