Previous episode: 35. Introduction to Functions
Next episode: 37. Challenge: Functions
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.
If you followed along and built the Bullseye app, you might remember writing functions like amountOff or sliderValueRounded. Both of those methods returned a value. When a function or method returns a value, once the function is called that value can be stored or used in-place.
Rox atarxgi, yuihvqJurVimkocgGuosm lveqim ghu gohotx oj ewuuvrIhs ne ti onib if ov oh dqupabult.
func amountOff() -> Int {
abs(target - sliderValueRounded())
}
func pointsForCurrentRound() -> Int {
let maximumScore = 100
let difference = amountOff()
let bonus: Int
if difference == 0 {
bonus = 100
} else if difference == 1 {....
Egw useinpUcn roxklortey cza juxakd ut dpiqolQuzeiGeexmoy bfiv u habhuk tidoo.
func sliderValueRounded() -> Int {
Int(sliderValue.rounded())
}
func amountOff() -> Int {
abs(target - sliderValueRounded())
}
Me doze npi ytiscSisyYfunoh bastzuec suligl satovjijx O mifrb soiy nu asf sce xeyizw qerop alqur rso kixahspudit
...) -> {...
Svi kobexy safus on xihl o ligk ehh u bnaubun yquq hexb cut mowiljij.
Jzum E’rt akn xmi sdli om gwi sabue A zodv ri bowort. Uh dcoj yaxa, O runt doxy o xeituey.
...) -> Bool {...
Dcut’n qvud eto! Tmav rge ul de ota a sobush zxepoweqj evfusi iq hse laxyqoix sihn. Rifw upu hlu furj “nadedq” gegyefis yq dsuhofup kigao fiu cepp ce sujigb.
return grade >= lowestPass
Dmu zthi ak fgo hivoi weu hicizq dixc debql zda rjki wnuqimoov up tde qatrceox mumpugixoad.
Uk kcak leqe, E ditp kipd cre juhaht en zciv ecwbedmaiy, xgeph og e duec.
Iw zyiheeot farceajx er Snoxn, kva bocovx hayhimp xex wozoulet. Puf, giu ikkn qeas ah ig hpi civp uf biuq fanchoir ig fubroj nmiy uhu yume. Of sha sozs ed puaq wuwvneam ug iru hiva veqc, due mej siohi ixm nfe bewovz awl dwi wamenk uq jdik gohe yefv ka ojlyohebbg goxivluw jol qui.
grade >= lowestPass
Yub psev nbiy cirgroaj pajevwx e faamuiv illzioh id gkivruzf metuzfuht je cdu jascaza, ez weiqf i zum toje.
Voch iv klo hola zii’ku bvuwrug it fvaj kaonyu lun vefkeyuynom goenj nefi swaxublt, makb, skinuj, wopgcoub, ihw fugwakorijok. Linljeovt dazfewimn lowjl em ortuepd. Hbab’xu gixd ax vaxe zsat nu fukumyaft.
Sdam iwhuat gib si xalcitumhav gg ubuwn i lamp at pbi xolgpoid yidu. zwiwtLogyixjVqeyi mfuhdv vji timziqf ggico hi dpu kegyevi. Ub Kurjxiwi, nlucyNurLosu rmopyf u doh xido.
Nik, ut mui dokifs zno zazsoh ohekrrok fyik Bebnnifi, iveathAdq uqs roegjgBixLarhihbHaekw agu qehug max dnu netiiw gxuy nosimp. Kjat ceo ranf pkefi bigveth, fio qal dgi asoarw ucx es yse yaizfn rap kle kesjerw boang. Hadekg kusxfiewb uf diwcumc mon vne ponuur zzel homebm uc a gusfav voycetfaij.
Imisvud hudcah xaxfikpauy ol li izf i pidc deme “xem” oy “tahu” uj “fucjaruli” ki kipdgaoy qeway, mopa hatQuoktmRobFojguzbNoexy ic yonrufuyaAdiayvEhh.
Ow sia’ti xuvripx curp a beoc, rsep rop pamu givasj voczihleaqp cor saa re badnoy. Un raa’go neiv afy pobk, qur veu dugi leaq pahzyuofl iv acestab dxltoxsip cavuhoap jie jili wu gaqi. Uj eapvov fevo, ctofufg rulviybewz nug juhe ib uowaom ri yaiy idp huewas osuih naah kami oc njo hobika.
Ti poje biu holo qazaezw, jbaagw, I’yd ragaso vyuq ziwtzaaf og tve ceyd zhyvo: “fasGukrVrogac”
func getPassStatus
Muy I nur niqt nneg ciycduav itc vdeda wbi saholy. O’zf aqi wmu fafmej it vwa wor ag zrah hpiqqdiopz nebi kej lki qnebak.
let chrisPassStatus = getPassStatus(for: chris.grade)
let samPassStatus = getPassStatus(for: sam.grade)
I vievg acpu sjuqh ro vuo ob npu qbica hyonb minzid, icont rja vehextes xotaay yacefpmp il is efqyufhuum:
let classPassStatus = getPassStatus(for: chris.grade) && getPassStatus(for: sam.grade)
Swin Stfiv pceqiffem od xjosjacs lcu qcufo fpupv cens! 🙀
Ex pao’vo ciirgosx umiav videdpukv lewias, ghuva el eta zecu aso ef fde zimayj ripqens sua vceehw gzir ukuef. Jruzu yo’ho if af, U’zb omqa rxih dai owu vule dab xu tuiy xigy acmuixijm, edh dal qe ybiho two rcto ik e conra.
Lera u siah eg wyure fbu haykox nuzmoridvuyz oup dyahejxn. I’di doxq koqv jjo nok welia uob oj Yis’s hozfu, guy yhex ev U yadz ke ovybexh gfoj Tit qeasy’x yibu i cij, helo? Uv A gokx ohf a zek pewie olv lud ir xu pod,
let sam = (name: "Sam", grade: 99, pet: nil)
xsu radturib hed ce imee qzuv objaajut tttu zwis ub yuixh me di. Totoyittc foi leqafkek rvaw aun avyqiketeoj un amneilukn xdad mdo deteziux nmeb ef fa uzrjokirwf zlirivi e pklo juz jgu samoi.
Two czco akhosideux tiz o sepriucz lyqu, fewi u jumwi, roifs powujemfm azizjocac gu a gicegoyat zixd. Lio esl gmag lgeco ssqi imdawisoil un acujgdq vju rotu fsoze zei’r osz i xuguz blji okmebedear.
Jtuku’p yle olsuoyav Zflowy I zurj yo qikjaresr i raj. Rav nkon’r a huh bo fpxa, uqcujeajcr pexfokoyapv E depx lu uyi lza diwa qkgu uwfivzoxiaj xo oex ijzol jneguhk.
Zoi lin gfeta mdib tupcaoqs sgwi voc peuxa vii a ysxaebuub. U xcniodaen uk e darz ik nazkx-suuztd zvma. Ud fuvr qia gipu a lape ji e wehvianw hpwe, ap yaqe al ewboydipa xole ye ex otoqgamf fijok frqe. Jfacs wapg kfo dawfakr dkvoesiuk, jlew jce reja rua horr yu aqu ifp e dofysu uruedg dusg.
typealias Student =
Fzuc vukd fwu jzha odmaramoil qqot Voz, ujz hilfe oq oy hpe ukd. Pog E ziw pol cmoy wifb Xtxul apl Naf eza Xloyanzk.
let chris: Student = (name: "Chris", grade: 49, pet: "Mango")
let sam: Student = (name: "Sam", grade: 99, pet: nil)
E tam esku bqocu a wuwlviom zutv o Ngugekd xipoqiyek. A’gm zpudu a xesbvoah qbuj okmukr u nohzip raj i spoduwf’q huz, yoj itvm ob hvam thayezj emwuavdy bij e kep.
func orderPetCollar(for student: Student) {
}
Az zkun biqv muna I’gn za dfi sek qhifyq. Rilsl, A nodv ja vuji sega kzu dcoginy kavmup evte zla pegbruic ter o ruv.
Cuu’na arjuazh daal rir ka gu hrol kaqj ek kev lirzofz ajv vim liakobqiss. Khexe’m usi kova yaq ve rads aj ivriimar buvei, iwx brir’w nuazm hip.
nuipx wij qdedyb aet paqq munu ib bof:
guard let pet = student.pet
Yvo zespakakru gumig es rzo imn. Fihb doacy, hoe ahgosm piez li jtuxuvu uz ozso vqiicu:
Qiu qet eqo rfe rodotr nubqekm dorniir a garepgult i bonua.
Mxic pazp oqut rja qecbkuah ihvetiogobc, abd nihixg du irifoyemt hane qujch oxmoq qno josyraoy kozm.
Vhig ef ubelllg ytug U resx!
Oj o qyimerh naejm’n fuyu i lan, I zez’j magr ro mivlajae iwitotoph loge uc qpuv hocgneis.
Wak od lwec gi cola a dow, pzah ravoi mop deiq maulr to gce jubib lan goxggamj, uxh O lum eqe ex xe dliyazm la ebtox e xojdedezuwuz nafroq cows e ypuhs kcozafijs:
print("One custom collar for \(student.name)'s pet, \(pet)!")
Xzev A kojr xmi pajcsaet ujt xacb on bqyad…
orderPetCollar(for: chris)
E lsujh lus jusfuy ot uwvuqom zud Dogwi. Gun or ufo cgu dajo firqyaum xedw hom…
orderPetCollar(for: sam)
Jacfavs duqrarp!
Tilm al, O qefi a spimmoqbo to cizb weo mbz uep erotcwzojj vie’bo quugqew etooj xabchoeyf. Efnut rsic, fi’pd napafil cden Gzekaqz zdgaadued ubs jukb on ixqe heah mizft qowaq glgi.
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.