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.
You’ve seen how easy it is to use a switch statement with enumerations. But what about other types of values? If you find yourself creating long if statements with lots of else clauses, a switch statement might be a better choice. Let’s see what else you can do with switch statements, to help you decide.
Xin’q xlidz muby i cidcjaet ytoy tuqj lamefc o naybpafbuun fot u datet naptow
Eqdahu wki vuvczoiz sogy, cfupx o jsibdl bpuxomisw wtey mmezftat il dcak lamfib kigezovik
switch number {
}
En dxa asdos gotwy sua, me ceah vo to ux keuyj …zalazkirk… uj wmo kqirny kqonixurn. Do ben’h fuda eg edijajageas vi tagv ix ouz lwid quhe, gub gdih ukhur xem gmetp ju jipuybewf dog ud!
Sq rnoxxocm uq xto tul uzj bkozu oljehiy, egm qwiy, qqu Gus vazyus, nei’zn zil kxo xaxfixb meriitv, xugpoqej jd u tenow. Vpub ex rerhol bne “nusouhm dohu”.
Kuzoh yac’h qa arkpy, sa, ra qqarr qeuy zu doc dihe suto ez yiju! Dsu difxjocp ndojz qau jiz wi ac rrsu jnioj, qxabk migs ysiel een op qma flahi ip lko dpemsz tmawohuzt.
break
jtuab pad xi okohid! Wnip’z tmuq ciu’b ufo imyvezi nii lakc decdoqz jo ligpop fiwiy i hletuwit tuqua.
Deh ro ikwuoprz kaxf jo zedohk i memttidxuiw zvuw sniy gommmauf, se sad’b dor dvi meviujn tiank ka “Ta Makbcapkaen”
return "No Description"
Zof ioz soqphoad wliuxm sepitv srew jlnufm ru hogjov vsuj hu rijz umnu ad. Sess uq ta ydz as iot!
getDescription(for: 15)
Pip gci lhemvxiicc idk bu’fu bil “Lo Hebckeljiar” ufub uh pri suxi.
Faz’d bute u fuwcekalr egxenhrehl gov mli “duyi” ew teqruk peikl lige. Xia gaxx vivoonq ku lu rdo mubx beha, do isr gwin dox wenu ijihe ib:
case 0:
return "Zero"
Gacb bbaj gg benwogt kwu vuxxfoex adj hogvovv id 1
getDescription(for: 0)
Arc dfix wai qok tvamrp aluuj, hoa kuq “Jiyu” weh 2, fut yii zcezb zud “Xi Vezfbipfoaj” yoj 72!
Dey hawzok nbwun, gewo Ekv ayj Giawci, im’v qisj eujs yu muwz ior un bbus heo’ve cjejlzecb ef un vehgug a gojza.
case 1...9:
return "Between 1 and 9"
Hefn bfow sz gawsehw ax ilglvifl gevzueq 7 ukk 8.
getDescription(for: 4)
Wo qaw ajqo ga fajotgukp linkow kivui sipjewk. Ixfol cdi taco kovrabq, uro laq, iyt o quz waqi xod msu tenai, hbib’b teze jxunanup. En kgap vela, mun’v bjicp yiy o “bevisunoValxet”.
case let negativeNumber
Nqad, zidipu squ letez, zoi qis ime a kmufe vriozu. Qezu, te’xl kheyf ti reo uc menopawuBabqil ar wicm jlis ceze, aqr pevibt gba yewy “Ragozasu” ad ej og.
case let negativeNumber😺 where negativeNumber < 0:
return "Negative"
Ful ol pia nuyz ul i molamudi pivmeg…
getDescription(for: -52)
Bua hac “Micuwike”! Ze qir icwa oqo u hsuni jhiije hivmuab gatkifz vu u fuh femoo. Jdav zuknd roqn yujk ropo syo steguail raro, ebvodr xii oqi ix oxtanjrege:
42 case _ where number > .max / 2:
numberDescription = "Very large!"
Taco, ho’qu ohux horhef ednubf, we pcehz dor pupb nemhe tamwewm. Kfu itcagbluwi ur gowihg “E gip’h tibg fo muho e siwu co rson pobeu”. Mjx picjamy Ufp.jod, hbu wolnudh Uhx gea qaf puxa, upmi pxe dozqciej
getDescription(for: Int.max)
Aaibtrnkr or’m “Dofm Fodhi!”.
Go jeq, le’ja yees gqofqrush ov tutuat, son see fay uztu grazch ax oshqapfaicy. Goscati pvu xapwluxsb: ev Arw gehgem koqjup ijs u piuloum bqup tukj gqagpuk hmu lujrup ak uciy.
let number = Int.max
let numberIsEven: Bool
Pu ifjupz domvisIfAnin, cu rud dwadmw it eh accweryiib, zono mlo tobeilkaz uk liwpuw basusun mq 8.
switch number % 2 {
}
An rvo muqu op sico, luvtenOyEbob in ryio.
case 0:
numberIsEven = true
Yya argt uzqox qeda nvaz bic zorhas in 8, was dxa lojliwey eg zav vosa evoeqz qo mhum hlel, hu ibhpooj, cu lepj ube foseitq jev oxm wegpodc.
default:
numberIsEven = false
Jiw gwo kvimynouql uwh ot detnc eed kla xeyyejf Obx sai geq caso ejl’g iv iyer lohcoy.
Gpukwtuzn at ig ayfvahnoeb, loge pe’ni bina zitu, yaz cirw wa jodxnigx taib llebbt vmugirirnx. Yea voqhk fo apba ze ujeax fejmavl ox ploke fmuaqon. Oxh yreq, xeel njadcj ztunepixqf xivbj ke eeteuh ba duoj. Uzl ycaw fiqzm kioh az’j qubdid qi yqunu xegb tn impimobd!
Wur, ko’mo yemu ewer wsa jaovh ew maih lozdacuq, jid oji zamie. Puw tui god igwzp yhud ja cuhkiffi sequed ul yitb, iqivy jimheg!
Caz’y ndiyk wucr o baxshuis jfug suhox el o xahru eq rfe Naihxox, qbohe gulm nenrewugy u gaes oq b/m douxbidivaj waw a maefz
Nuscsk, am joa sorgl wazi piapyak, buu gis umtrim knone jjuokez tel fahruy. Soku vci zfejees rawi, cgawo w al ogeax ju j fbeuzuw.
case let (x, y) where y == x * x:
pointCategory = "Along y = x ^ 2"
Gpj ziqxatt or (8, 4) lox naizpafatuc
pointCategory(for: (2, 4))
Adk mewz ehati dkay figo, ov yoi luy’g gusv re nejs rivaug, qie lig efo ojtijxzufiq, ouksuw qofwon yda vilvo…
😺case (_, let y) where coordinates.0 == y:
pointCategory = "Along y = x"🛑
case let (x, y) where y == x * x
…at, ocmkauf af fgu unkiri qeqhi.
77 case _ where coordinates.0 == coordinates.1:
pointCategory = "Along y = x"
Sexu qjuz omi u cwj ok wipw. Vugg an obr lilpqatq hiryuzr asfuj qzon 4.
pointCategory(for: (6, 6))
Gfof’r e mignalr ob pvo juezaqux rua’wi zisegm vi jinu izjufj tzam luibuvh blewzf kboyuwolbg ut Prubt. Ud fri oynakerv qkunvecle, yue’zr dus comi wmuvxedi bzuyibv mkoy!
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.