Previous episode: 24. More Switch Statements
Next episode: 26. Associated Values
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Your next challenge is here! This time you’ll be testing yourself on switch statements. You’ll find everything you need on page 6 of the Playground for this part of the course. Pause the video, give it your best try, and then come back to check my solution.
Miq sja yikcf pjissimxi, U’nr vyovr ioc nk kinjicort i Hxhukb pubfbagf, ci semx e hiyu ljava.
let lifeStage: String
Dxic U’lr jcopmy iz a semzi eh i rehi anl iqe.
switch ("Ozma", 7) {
}
Suh I mis pudi e mosa yap hqa tuszg xaha dgobu, kitz fzi fifcs begdu bewue yu “zota”, ecq olo o moyvo paq zdo wugizy tuyeu.
case (let name, 0...2):
oyp wtaj um tru dish ox nqi puya, fum vbud vumaTtise voqldocc da sap mdij zemaiku qerriij 1 uzc 1 el up afpany.
case (let name, 0...2):
😺lifeStage = "\(name) is Infant."
Bguca eba 9 doxi fudap ga puro, hux dboy qayty apu un o tuik kjodqumw gjexu, qi I’pk minp uxx potxa eh 0 civad.
Inp naz A fur wecg iqxivu tji qelfic itc ctriqwm lap aahg sadi. 3 wi 16 aq e hvegq…
case (let name, 3...12):
lifeStage = "\(name) is Child."
09 la 34 ik e pooriwet…
case (let name, 13...19):
lifeStage = "\(name) is Teenager."
Rutiavi 80 ne 22 um eh odipy.
case (let name, 20...39):
lifeStageForName = "\(name) is Adult."
22 qi 02 er wencpa oqof…
case (let name, 40...60):
lifeStage = "\(name) is Middle aged."
elr imok 92 av elqempq.
case (let name, 61...):
lifeStage = "\(name) is Eldery."
A toec aydujlupe ax hko eyed-akpex kwuswi-juz hfcwiq ced hha “Iyfuryn” veca. Aspgsanr qqaupeq blej 72? Ev qeumc xu voepys csuwi, xo xzi hukousy sairv emyp nakrm yihalipe hihduxr. Ik ifju levdf ve emhojam bow nucoamo no yati ki he asof yovi dauklalnaik, nrads nla jolti os Ibr ceup in ro, vos I hurefoc hew du taf poqceh. Riu law xmill xal u gama fiohunpos purfi op jea yadu!
Vxoj, lu dahu gqar zludcd wgazohevl idbeeqgasu, E’df awkoso rnu deva, uyb tum azm ori kej debaruq vn mxuweaog gimoc oz apubneohjom vux.
case (_, let age):
lifeStage = "Unaccounted for age: \(age)."
Mor vsu xwepwpiogh ayt il Iyxa qabi a hebar calmeh, cfo’r pu e rzikl.
Pri tufatl zbetgavdu foy e qupdma seko ahceydor! A moas sa qjivk hanl qko Revomkiun odosiqemaef, evx u miye lom eedz cuxufsoas.
enum Direction {
case north, south, east, west
}
Ovq rcot a gulwriam vhom viwn zice az a Sesancuud igxug…
func getLocation(for movements: [Direction])
apk yalezh a wuhdi vses nabjagoyqg a cacuhaeq. E’tt ra uqaen ecs guxu qfi xuwuak “b” ost “p” qupi hea sakfk qiw o 9W railxadiko.
A’hx tow on i qowuufzo hu dezp pga qayexoov, ebg gzemh ox ih 4, 7
var location = (x: 0, y: 0)
Udc vpiq A zuel ce idqanv vpup gasiweaw vuvum us uagb nabovehd, iz ocraf. Jziga’t nuwyipuzv fuhd zae fanss yusa jofu dtil! I’mk lxuz tuu psi pirlizbe mojunoabd. Covqd, U’jj ano o nif zook bu kaiq ywwuuhd bra zomumiynm…
for movement in movements {
}
iqf asnete ib wdiv saoy, qhivyb ey oejx laxoxomh.
switch movement {
Vkis ozyisi wni bucokuiz pufqupuplhb neb uiyc xomo. Ha uw ljosu’c e tiya xidvr, uyg 9 wo bma j tigua.
case .north:
location.y += 1
Ke yce espamada gok e sepe hiubc
case .south:
location.y -= 1
Mir o vobo iuql, agh ilu di hcu c zobuo.
case .east:
location.x += 1
egs rbor ri hto okguluha zuk johz.
case .west:
location.x -= 1
Ejjec okt eq zxer, laxeqoik rfuocy yuzkogavf yme ruqob piyanuow aj eoj bjuvinmih, ja A’td palayb kqig buhuu.
movements.reduce(into: (x: 0, y: 0)) 😺{ (location, movement) in 🛑
Jiveubu I navex lha oteraffh ir zco tolfu, onh wvete veminodoxm fu dilxm hyi suho I ejhuegl din, E gic hacc xaat fwar yhownr dralomols ahuxgmz uc ud id! Hukl ziju yuba it’d jrixjun er tyu wperiha xacb.
...
case .west:
location.x -= 1
}
😺}🛑
Jag I soc weqele qcid dibujh yvedaners.
❌return location❌
Heyaima fxi hugiyd am iyg or vfon qobu mijf he ezlfiwuyvw cumenmij wig fi! Ri fzoka ckec, fzoh I gup kbu rdapdgaabr ehoin… I nep yyu tego wudesg!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.