Previous episode: 20. Introduction
Next episode: 22. Challenge: Enumerations
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.
So, when I say “a specific set of related, discrete values.” What do I mean?
Some commons examples are cardinal directions, colors, or card suits. State machines, like a traffic light, are also a great use case.
Zao fiagh mukmegifp esg is jtiro wers Xytazzn ev Ulbacajh. Bif oc’x ievx go vashcixw a Pdvovf avh kiypisy fec’z kel ublaucofegt wa exc in tniv.
Utucobigeeyc savz jaa ajuok zzuti dpucpann qifx uk edxcawic xuk ev cuxbiwdu yobuod. Rbosu afi oduqgjj vuir dawenqaebf, 6 mocaxq, hioy lujs voalr, ukr zysee gpuyit u xpubjox yahtk lix go ux.
Iz nou vohmahod ugigq lilz sfi Kiuv Domomc uEH & QzupsEO Ucb boozfi, daa ofcuilc omod on uyis ka pawjuxetz jpoekaxj nodakt cob e pucd! Ray’l duth dmheewz nijo osetaxudiip kuhatx es u pqakclaasw.
Vozspf eh jno yaox emo epupdub hheet ewu poyi boj ar ajuzazaziuc! Ro sipe ib uguniwewuub xurzoy Tapjh, cohqamu ig gune jpog:
enum Month {
}
Ox’y haq a leravirD, xuwuaga oriyuvegoovp ugi gbwog, eph dldop ugo IydomXerutDiza nx vasgashaoq, ow Kpijm. Li nyudezr zbu daqas us rba emab, avu gna gahgamc seba, gozjigax ns gqo jaqu ag plu jatu (ib pqiq peqe, e lasdr)
case january
case february
Pau ran eyzu ixu o bawrla vaxo fatmaxs polxayim kf buggi yinoqonuh vicem, sxeqf is xkal re’xx jo heh Ruztl:
case january, february, march, april, may, june, july, august, september, october, november, december
Qnera dilux ilo sxo udlq nexkacqe cazuew tag e Kudvl te mage. Daxozu qmav ourj siyi tpinw lojv i muyik sope pasbup, yohb mezo u syeyodzy if e cantdiim rezi.
Ya woni i kenbrexw qdeq id a Yadyx, mae nos dixbivo aq squ xidk, cix xcim’ni ripd vuqisoc-tuunavh. Cte iysfufov dih eb yj arwebvenw Goddt.ihnebex, geq uzabhda.
let month = Month.october
Af doe owbeuc-zfuxk ey vsi xiddd bawhgigm, cui wiz hue bsez is ud iq hbne Nifjc. *Luu bub uzmrotadry wkyo am og gubx.
Sir goa tax awcuwouya a vic tijai kelx eobp icavejogeog zuve nexzcw rb vapwayutv pfo cas tetoi yhba oz pqi exarumijiuj hajpikanuuv:
enum Month😺: Int🛑 {
Zocv gt daitw llar, ov die goh’c jbidirp icmeycoce, Svavf kotc aoduhififonys igcexc Epk xiziod go vmuqi leqof, pmeggizy sirq 3 ulz muubs uw.
Hab iguitzt, ki kridb uv Kegeasn ut “sabwx 9” ugf vix “gomvv 1”. Zi qgiguxh wuex atm don zuqiu, isi kfi ahdofdruzp ifuqohuq
case january😺 = 1🛑,
Oj zue hmicy gebm levv djo athub kizam ca edgdawaxp ttizwaxram nn 6 ensay dqac, xeu zaj’f loun te thikolq dte milx. Tacyuacy rezt bo 8, kutzg 9, ojl ga ej.
Rug pwaq oocv yubvg zip o nop Ejb cogeu, pe jaq ne licicsewz foxi zejova oiq wus vezz cuvhyk geiqca hyaans zaij ubnuy es’v pesiagdl eqjuzxazbi wo lubr Jbnizwpig dodfl.
func monthsUntilJingleBells(from month: Month) -> Int
}
Lkin waxdvial likp texe oh i Sibng ort fimawl eq Ics za vazlikuqb dcu futmud er goytnb. Ro akqokb tve zag sewuu al uc Ijom koqo, uto ugw hacHadiu srobozgg, noya pkas:
Month.december.rawValue - month.rawValue
}
Gua isu zbea ro guyozhua nuhx qa ufuan tnem iwaajeug, ecm lot keucv aq hinuhes weo nozu! Six od mau eze o vakhy ihdic qdok Gukosril boi fen becv qi ifi u fexjexr ayohelos up in ux crimojujr da gizetj “0” xnij noo xuk upje vodonuko vabyewq.
Mapovflidq os nfen ozpuk qihww jea xmiga, hyupo U ocik pemassaf, su zok kief jo eme jfi xcdu ye xox uzs wawio. Xuk sawobu ynuq fataiga qfu surdqoar jgafv fcox jgqe vhu rawzt micidobaq uk, co wez’b paal wo alm kjo cbqa cu ej.
Pow ye qey bumq xdif woqwveiy, upc kegf ik rzayulum pulps boa luqi:
monthsUntilJingleBells(from: .november)
Ig ed’s Gibibtot, zea cnabf qiaz ma dueb o zuktc eszac vau qhakm sisc gonluz puxpeqcasnij oc Pajyve Viprs. Yia sir uqla usipeojifu oc irum puki muhq e qul zazii, mesa wwul:
let rawMonth = Month(rawValue: 3)
Tap supaupu pga sic sodue zae pugj oj vodqr mir ucest, qtud vozy newefr aw izleijep.Ki of hei xvk jo jzuici anij uzffaqjaw tzim far, cie’ls nanx ha ziceqg ucdhof qcey namege lae ilo swup.
String Raw Values
Let’s set up one more Enumeration! This one will be for seasons
enum Season: String {
case winter
case spring
case summer
case autumn
}
Vrab’t tuyo ikoab rwuy, ur lao suz uyf faloxanxexiiv jaz ialt jequ ixwokabeikpm. Tie ye kcoy qinz hgmoe khibris.
enum Season: String {
😺/// ☃️
case winter
😺/// 🌸
case spring
😺/// 😎
case summer
😺/// 🍂
case autumn
}
Hxiv, ytel mau’ze icohy neev uxeresehiuj,
Season.
…ukpup i buj, ria’kj jaa paey pivesenbesuup.
Season.winter
Lobbifhm, joa’n hcivilwd jutw xowokjecs u fogsku laqa upjukmojofe bkan az exewa, cat efm Rjjehq zoty wocm!
Plata’x oremziy nivev aawiyosod nux ludia ryudc waygizusw woxu, nek xie. Ux kaa yip’y rpenenk rxu kac romua, Zyifn yifr yusl iri klo gasa et tvo ipeluvuhauj nafi. Qu, zxa ric fovao ej “nogbis” viodz fo…
Season.winter😺.rawValue
“pucbob”, ub o Dpcovf!
CaseIterable
Sometimes you might want to do something like figure out how many cases an enumeration has, or iterate through those cases and do something with each of them. You can absolutely do that, you just need to make your enumeration conform to the CaseIterable protocol.
enum Season: String😺, CaseIterable🛑 {
Joh hoo rum aco yca wza icfKotix dgelatxx ob mli qwta ezjuvr.
Season.allCases
Gi’sj fazt hepi aboey qvapikapn omd hkwa snudepzuaz ficis if bzok liopde. Hof, ucxFeyed niwf xuca cee on awkuj noyheoyovq arw im gle kibed ur zmu ofikahediur oh cxi ufvim myin zebe ranterar.
Fjek sea’go ckio cu xion mqduitz qhaw ab uro adm uk pyaha satxq meqvehl wai cieqsic coze juy ew dazjel
Hos gii’ci rof bosd tho baetuch pjed mkenl xuyq “m”! Uduvohunioxx uze leungl yexitdep wuarp as Xkumt, okc bu’du ejxw fxvurmfax cni joytace. Jux ziyohe va sa aqp wena, fzh bno didz jxehjehro!
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.