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

Logic for sorting players wont work

here is the code:

// All the players Info In a dictonary

let jSmith : [String : Any] = ["Name" : "Joe Smith", "Height" : 42, "Soccer Experience": true, "Parents" : "Jim and Jan Smith"] let jTanner : [String : Any] = ["Name" : "Jill Tanner", "Height" : 36, "Soccer Experience": true, "Parents" : "Clara Tanner"] let bBon : [String : Any] = ["Name" : "Bill Bon", "Height" : 43, "Soccer Experience": true, "Parents" : "Sara and Jenny Bon"] let eGordon : [String : Any] = ["Name" : "Eva Gordon", "Height" : 45, "Soccer Experience": false, "Parents" : "Wendy and Mike Gordon"] let mGill : [String : Any] = ["Name" : "Matt Gill", "Height" : 40, "Soccer Experience": false, "Parents" : "Charles and Sylvia Gill"]let kStein : [String : Any] = ["Name" : "Kimmy Stein", "Height" : 41, "Soccer Experience": false, "Parents" : "Bill and Hillary Stein"] let sAdams : [String : Any] = ["Name" : "Sammy Adams", "Height" : 45, "Soccer Experience" : false, "Parents" : "Jeff Adams"] let kSaygan: [String : Any] = ["Name" : "Karl Saygan", "Height" : 42 , "Soccer Experience " : true, "Parents" : "Heather Bledsoe" ] let sGreenburg : [String : Any] = ["Name" : "Suzane Greensburg" , "Height" : 44 , "Soccer Experience " : true , "Parents" : "Henrietta" ] let sDali: [String : Any] = ["Name" : "Sal Dali" , "Height" : 41 , "Soccer Experience " : false, "Parents" : "Gala Dali" ] let jKavalier : [String : Any] = ["Name" : "Joe Kavalier" , "Height" : 39 , "Soccer Experience " : false , "Parents" : "Sam and Elaine Kavalier" ] let bFinkelstein : [String : Any] = ["Name" : "Ben Finkelstein" , "Height" : 44 , "Soccer Experience " : false , "Parents" : "Aaron and Jill Finkelstein" ] let dSoto : [String : Any] = ["Name" : "Diego Soto" , "Height" : 41 , "Soccer Experience " : true , "Parents" : "Robin and Sarika Soto" ] let cAlaska : [String : Any] = ["Name" : "Chloe Alaska" , "Height" : 47 , "Soccer Experience " : false , "Parents" : "David and Jamie Alaska" ] let aWillis : [String : Any] = ["Name" : "Arnold Willis", "Height" : 43, "Soccer Experience " : false , "Parents" : "Charlie Willis" ]let pHelm : [String : Any] = ["Name" : "Phillip Helm" , "Height" : 44 , "Soccer Experience " : true , "Parents" : "Thomas Helm and Eva Jones" ] let lClay : [String : Any] = ["Name" : "Les Clay" , "Height" : 42 , "Soccer Experience " : true , "Parents" : "Wynonna Brown" ] let hKrustofski : [String : Any] = ["Name" : "Herschel Krustofski" , "Height" : 45 , "Soccer Experience " : true, "Parents" : "Hyman and Rachel Krustofski" ]

let array = [jSmith, jTanner, bBon, eGordon, mGill, kStein, sAdams, kSaygan, sGreenburg, sDali, jKavalier, bFinkelstein, dSoto, cAlaska, aWillis, pHelm, lClay, hKrustofski]

var experPlayers : [String : Bool] = [:] var regPlayers : [String : Bool] = [:]

for player in array { switch array { case ["Soccer Experience" : true] : experPlayers.append(player) default : regPlayers.append(player) } }

Im having trouble finding a way to append one of the players into "experPlayers" or "regPlayers". Please help!

thanks, Jack Colosky

Hey Jack!

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). =)

P.S. (good luck Jack let me know if you have some questions this is just an example its not how my code is so feel free to play with it...)