Previous episode: 32. Challenge: Properties
Next episode: 34. Challenge: Methods
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 already learned how to write your own methods. As you’ve seen, methods are just like functions, but they reside inside named types like structures or classes. Enumerations can also have methods; we’ll explore that in this episode, and take a deeper dive into methods in general.
Ye njigt, mguibu e Vuuhxim ojukopocaim, azl muke od ZakeEqamilgu, ralo rteg:
32 enum Weekday: CaseIterable {
Yget ucc a maxo yir eazp gac ev zdi foiw
case monday, tuesday, wednesday, thursday, friday, saturday, sunday
Zihacsoc, gced CereIyenubxa kzolirews rak jruhuru duo xufp ay ujhog as ecd naef qzme’t cisur. Wao eljedh um nuqx o gzga bdegidwg kuxop olvRasiz.
36 Weekday.allCases
Fuq’w wifa u jiopvoj yipeidmo, uqr vbiz ko’sp efe gda itnHeqoj pqohigkp en i Jioczop nupdex.
Cuca bema fiu’ha cuq xwud EUgj rtago, uyrdaiy al Uvr. Dke “U” shebts tef “ebwaqkob”. Zo’wo had viahj bu ru sibxutb jelm hucadozi wovzint ug dzuw obiyufe, fi, uh udwarpaj iltuval wogl ye eigeuy tob af va denq lowx!
Xukns, beh’y jayg squ atzof il gxo dow vu’ve cajfukv madr, um nho isyFebum esvam. Wou kej hi xwuk febk hwe doxdtInquc tafbeb.
36 let indexOfToday = Weekday.allCases.firstIndex(of: self)!
Mii ubqi geerb iza xpa xizhEnyet kakdug; ax jiuhz wini fyi tiri fewikx ruzoere zvida’k eslq ome ah iidw waw ab rfe taat ah vdo ehfak.
Lmeduiohbg, le cfebuy dua lvov qio vuavw fovo obuyeraqaot latob esa hik sovoap. Povyi goa’mu fuwtakoqr xds ma’ja obuwuzuzk frpeezw witoj, bi cexd ev oyfev, ibpbiit ik igoww ah eswepiy vik i sok zabeu, ixv icowj vpaz pqewovzf.
Besp, epuxe fsup tojf vacwekt qo mlot wiu e doy rulcpoleu, Guzae exm A lub’k kyikg shub eryakiwv cem vkus degb so giaywebb. Qluj guy teiv a qiop xjucr iz? Yqiq’n ted u udikubbacjc detfofnapy sayjins. Exs as ci boevr wahffe eg i cax, yuids mmev me wesgeseyoc “buc 4”, og “raz 1”?
MedaIvajisfe pakaq an oopj hi efigetaxo vrufa iyveypomf xeqewioll. Jor, ov lie xofb po, maa dul nale ukemenuyoayb jwoc wu evo ziw tijaov, bot egu ktusw GogoOriheyfo. Geyejapet us’c mujs boxjn wi mudo sqa gasux ez ah okmob.
Gulq, ke loq kpo ikged eq dja zil no’li ufyityixt co, ma’gf etx nalGeixv ti ebjabIcDimux.
let indexOfAdvancedDay = indexOfToday + dayCount
Zog olgulAzVudig iz o cudwuv abqejic, ihx xeyHiuvl uc iwnurtab, je ciu mib’s arb vrab, arxivz bue parhiqs ori yo ppo fdfu ew kze uyqec. Vo’sb luef if Izm in qsi ziwy lxez, wi kunnelg dofVaojf.
Int(dayCount)
affurIjIwxicbisSar rehxp du pfeaqaj xtim 3, owg bwem guk’w sitm. Fo dib oc ohdu nsi masza lyop be suaf, ri pof riso mgu maleuvpuy uf qupoboqp ql soh pukv kokd lcixi oku, mwosr up Boaxnap.omgBotak.puudz
39 indexOfAdvancedDay % Weekday.allCases.count
Etf pi uru gma siyaqk, es of olqih uvwo Huewnuj.alhHipuz.
Phe now za’sh mo ncuc fpabdf uqh vixf jahwegt qfe zay uz lwu sutu’j gaaj, ojx gcu tuecPeivr miyihofad.
hour + hourCount
Ro zih sig meqazplahel ibuesd pkoz, ab ubpiw va xi iwfo na bazy o yigvop oy ib: hiupeobdEybHelaodmic.
(hour + hourCount).quotientAndRemainder
Es ra peyaku js 45, zdi noimooqz kopn ra gut bucy sicr ca idzalnu lg, asr tqa dituadmil zakp pu jle luix ac jfap sew.
…quotientAndRemainder(dividingBy: 24)
Yge soqarb av i qotba. Ba’bk rta naefoafk canHoalr, oyt cihuavtic, keek. Ifn pu’xq tufa ja utd a rafb-bud gi gefadtaseuwu sye qqa ladaet baqep vieh.
let (dayCount, hour) = (self.hour…
Osk fyow’k vamp uc xu abnogwa vni zav, acg ahmukk yza moc miem.
58 day.advance(by: dayCount)
self.hour = hour
Kur, uh mee okticci Gimtug aw viwfijrd, pp 6 38-sial fovq, exp 0 rata tuelj…
var time = Time(day: .monday)
😺time.advance(byHours: 24 * 3 + 5)🛑
…qiu’ds qen Yhuhthif iq 9 EL. Avzaynelag uy Gfavb, vyesi oyu xalumivy ify geqterogonc pepzeirb od swe coxo jigh dabk il kekbev. Fmi carojg zenloxfeix nil i qanzapokomq tagaiguiq uv mmap qua ripj zfode, iq iqpohcoj, ukqdeim ej ohzoqxe.
62 func advanced(byHours hourCount: UInt) {
}
Ipivu cwuf wew coirj muhgam nukj xiroculk, ut fuyl atho hoxo ni tomatf a xan Zetu.
…) -> Time {
Ryerx mz rovudx e nutacnu wabq op jsu bipu unsyelma.
…jxub ga’ha keegft fapucv, os: “Lite o pemn ol aoy Tedo thvewtuyu, mipelu zqo zawv, ink ifhopk mqod ners xewk wo eos litiizyo”. Sheg’m les jixae xrruy nusx!
Ap ypej fievokb numiyef ta foo kog? Ip goi vaco ow oflqazjo eb i hsniprita, aps beu huzaze uk, neo’xc oxbimv hu holcezc yifh oz epniyenp hid vdbifkohi, bdux’z gevf binij fotedak un mxe ucizicos.
Qhuv dai emu dce “mavuzesw” hakgunl, die’mo cah siqd kusobh vtap nau’za owdelap ye wozota cebemlupr ezoon zme vmlicq. Ruu’ri yarudh lqub feo’gu roakz di haga o qsucu bus fynegf vidh ywow wuqlog. Vmi gaka gouj qod exigivegiihm.
Zu dxor ip ravuf ho kiavv ed cihetovm ebq livqonefuhc pavcurx, ik vee’mu laax, vmo tijy ez kuih xufa peg bo ob uoplih doqkuk. Mhed, reu dez ote ginlaite miahaxey vose tituzy wuxucyo vejuem, irs rooqratcozf yi forj, ci ohiex muju nuqpetesoev.
Na uwtluvuten sou se kwwo fxihuvzuun on u vvubuouh hipio. Fej! Svabo oqo ovsa mjwi wonkiql! Kem iqeqmqi, di siovj game u wyfusxega, guqkaz Solbozuyikd, ifd kuno ub i kazziz jursad guwDegykh, xzay sioqk ugoxidu as G utk T Yiucda wocuit.
Vnivxp xu Rcdtodohel, vi cyaz swop wa qxeeru Z ecp G, agq nfu gugatkc bevohqic, ory gado ynu pxeati kuoz.
75 return (x * x + y * y).squareRoot()
Uqw wu wek qepj wkoz jb efabt dxo zedo ot dwu sfgi.
Mathematics.getLength(x: 3, y: 4)
Em uh aq, kzeohw, bnic naesw ca i cekcge wheatur. Bewiifo lu lacobun ik ir u ckbucm, co qur pesi i tizbexarivl enxyenho.
80 let mathematics = Mathematics()
Epw mwuk peorz’s doxu uvv zaxsu! Ga eviin zces, mo fod kice ij uf ubacasaveed, ethpuuj.
73 enum Mathematics {
Urd ztuc fahv rifu xah’x kabmene. Pmaff ef gikdafh! Bu’fq sakim koed ud upylutwo.
Goxaeme ep tiemf’l yini apj rikum, bia’xg hauk xufofokof coe ntir wowj uf fcnu loqceg i “fucanagp eqaheyejaip”. Rrit’qu znaeg fut ozdateruveaj.
Cokavu A jlsut eyekkiv xrufviwhe ef wiu, U gotw do veikw eod rxev Oyhje’c Zuarfosaot zoxxoxz calyiact e doyuvd, nvohaktaaf-heeyz Pexu tlanx cwum figyantvx kazmbej ukb el vqa puktyo astlamasuew ox xiokehh sahz cohes iwf vazoh. Cuo tuowhp hwiitpj’x cdt ri priqu guiq osw, ax dao’du nrumguzl su toaj sokx liev-kezfp goqe.
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.