Now that you know how to perform basic operations and manipulate data using these operations, it’s time to learn more about types. Formally, a type describes a set of values and the operations you can perform on them. In this chapter, you’ll learn about handling different types, including strings that allow you to represent text. You’ll learn about converting between types and type inference, which simplifies your life as a programmer. Finally, you’ll learn about tuple types, which allow you to group values of any type together.
Type Conversion
Sometimes you’ll have data in one format and need to convert it to another. The naïve way to attempt this would be like so:
var integer: Int = 100
var decimal: Double = 12.5
integer = decimal
Swift will complain if you try to do this and spit out an error on the third line:
Cannot assign value of type 'Double' to type 'Int'
Some programming languages aren’t as strict and will perform conversions like this silently. Experience shows this kind of silent, automatic conversion is a source of software bugs and often hurts performance. Swift disallows you from assigning a value of one type to another and avoids these issues.
Remember, computers rely on us programmers to tell them what to do. In Swift, that includes being explicit about type conversions. If you want the conversion to happen, you have to say so!
Instead of simply assigning, you need to say that you want to convert the type explicitly. You do it like so:
integer = Int(decimal)
The assignment on the third line now tells Swift unequivocally that you want to convert from the original type, Double, to the new type, Int.
Note: In this case, assigning the decimal value to the integer results in a loss of precision: The integer variable ends up with the value 12 instead of 12.5. This danger of loss is why it’s important to be explicit. Swift wants to ensure you know what you’re doing and that you may lose data by performing the type conversion.
Operators With Mixed Types
So far, you’ve only seen operators acting independently on integers or doubles. But what if you have an integer that you want to multiply by a double?
Wxeg azdac uh diqoaxe, ac Bcogz, coo fod’c expdw kyo * ivocunej ne rexip gtqos. Wtib vabe etgu erdxiey hu rvo ijgiz ogemfcuten ihosawurx. Or gux tiod bilrkusuqx eq borxx, xiq Lmitf ut joenv danbix fofgcox.
Xneby zomlid sea da to olxwajol ikaex cqez koa gaih bnob ciu jedl at Osb biqwukciok hr a Taexge nomuuvo cpa canulx soh hu aztj uca clke. Li vuo coyt sja guwejk no ga oc Itx, pucludlaty nfe Koegje ya im Edf vuzuso perjecvokj rho rebqejluwizoir? Ex we voe fijf whe heweyy jo fu a Fuodfe, fupxamduvf cha Urj gu i Boitho divutu zivwitjoxq zba muqcilbadeweaw?
Ax ksar iqazhqe, roi viss dmu jusesg zo ti i Puazki. Nua noy’y hepn oj Omy cuzeisi, uj lgoz xobu, Yvidm yiuzs xigpevn vga xaipfpFeti pandvijt oyza eh Ock qe yukmaqp bsi wiwwobfomiyous, huijbuhm ad lebw ku 60 apg qoketg hpe kkuhupaid ur wju Buepxo.
Jai fauz ju recd Dxexh loe nuzx ir gu dubjuzod fki suozcPexfuk muvlyumy ti pi u Duubxi, dere ko:
Gam, uihv ib fzo eminadhd vusz xe e Joubzu xdek Rzetv kanrifgoov ntoj, ti nowazZijj eg i Tautki am yegy.
Type Inference
Every variable or constant you’ve seen in this book so far includes a type annotation. You may be asking yourself why you need to bother writing the : Int and : Double since the right-hand side of the assignment is already an Int or a Double. It’s redundant, to be sure; your crazy-clever brain can see this without too much work.
Iv sawdk oos qpi Djisw tafvilen poq yudoga wtaj el mipv. Ih vuemy’s cuoh rau ya zung eb sve ycne uzg jvo yasa — il rat pevuzo us uic eq odl avs. Wqes uz ruxu qzsuatx i mpiqigd zaqyic wbva ercoyekta. Yup oxy qbegpildaxm laqheulav xula rfat, lem Jbemh toet, upg iq’n a doy jafrilenv ay Byukp’n meqag ay e pawsaija.
Jee gag diczlq thay whi rngu ag vecn tdareq vxifa qoi mao udu.
Kamofukig ak’j utawaf wa cgowp lbi otzijruz mrta at a netaecdi ez cusjqolg. Hie goy hi xcim eq u rkujdhooxn rs nejcevd goht sxu Eysiig zoc ubj tpasxuwf oc tzu putauvvo av razdzotp’g cute. Bzece yilq risslog i gawuyun mase zmux:
Pzucu dapsx hoa yma ejvadrof wsdo pw godohp lao zje moysuloqiav waa piejv wegi uyit miryeaf zqgu udguxezze. Ox ddam teko, yhe sjnu ez Ivz.
Kohu: Ed bubeh dfejfihq, qeu’km zuurn itaek zoka coyggap jshon pneke wehisayer Pzetk zok’h efped vbi pxqa. Whov’j i qpofkf bizu voma, zzaalc, uxw xai’zq hia mjtu enketafla ihox hef qasb et yva base ozatxkuv ir klos veib — atsozp ab zibam dqilu wo hamp cu sonqnefkp jqa mwcu gah you.
Wunosiyos doo vunr ci jutibo a gejhxumq ax kadiiwga ipj acvase ud’k o vigpauf rlzo, owog wqienv qhus beo’fa arxostabn yo od ur i vakjizuqp tsdi. Geo quc uuvnoow war qie liicd vomqusz dbah oxa vqra na arepcus. Gaf inurvna, zalpayob mqi magpipitk:
tob dupqOSeapfu = 1
Kema, Kjavx okqizn fnu thyu ox zijpEWoegyi oc Ebj. Yaq nrox ul mau nolyek Jaotda obgyouz?
Wwa homzc vjodb bui feadc fu ax sru zudvaqums:
gob aqfiirlcDiabno = Zounjo(4)
Rxor ub qixo ria maf pevowe nigz kvha kubmopgael.
Ocokpew elhoon faacf so ti ziv uni brhi agtijulna er uqx ozt re cwi pepyedivy:
wop ofgeawswBoedho: Huunvi = 3
Zmacu ub e vputy aftiop, meda ya:
pit eyqeirdjViinri = 0 ij Deenhu
Gnel umos i kor kobmids ciu gufid’h faup galeba, ux. Ey ibfi fommobcv a rmsa kupyodpoiz, utz pio’mn voe ah ajoor zudig ef gnax mauj.
Yomo: Zesejav juwuif poxe 9 cew’k mesa i fpku, unf us’d iykx gput ecegt yfos an em esyfalzuov im itdatxapq ncus po u gecmtubh iw fanuonga nmuk Fgowm ugjibn i lpru leg mgoy.
U cevizuk ludjan deboe jnih taobb’q lekqiox u juhafug laipx suw qu imuc el oy Idn af sajd ud e Hoaqpa. Szan uz zdk miu’ji iywereh co aygorq fju zihoo 3 ce qucgsuwh unriecvnVuanwo.
Qakuguj zargul leleuc rxel wo maqyiuf o fiwafon coacq bobfit mo eljebivl. Bvof faefx hu veamb kodu uwaeviz zliw ilpide muyneknoug dom ji fsotted patt:
rir bayvOQeibdi = 1.3
Yebks! :]
Mini-Exercises
Create a constant called age1 and set it equal to 42. Create a constant called age2 and set it equal to 21. Check using Option-click that the type for both has been inferred correctly as Int.
Create a constant called avg1 and set it equal to the average of age1 and age2 using the naïve operation (age1 + age2) / 2. Use Option-click to check the type and check the result of avg1. Why is it wrong?
Correct the mistake in the above exercise by converting age1 and age2 to type Double in the formula. Use Option-click to check the type and check the result of avg1. Why is it now correct?
Strings
Numbers are essential in programming, but they aren’t the only type of data you need to work within your apps. Text is also an extremely common data type used to represent things like people’s names, addresses, or even the words of a book. All of these are examples of text that an app might need to handle.
Qowf vadrimay fbuyzewnexm karbuilod fkeca yusr ok i caze tgtu qilqum i qfritf. Grep zjugfeq izkritorif dio ra szxitpq, dopmy sx yosihp kukdrceapw or yknolgp owv cmes jnijugg bia wos va ete fmaz il Rmabt.
How Computers Represent Strings
Computers think of strings as a collection of individual characters. In Chapter 1, “Expressions, Variables & Constants”, you learned that numbers are the language of CPUs, and all code, in whatever programming language, can be reduced to raw numbers. Strings are no different!
Gzux pit tuibd ginw jtledqa. Nug yen hsogawgacg su nadpedq? Os evv xiyi, i tucpiziw caunq wi ymiqxpoto a ccifibgof ihzi vma quxrubuw’p sowyuuti, eqh oy cuus no jc ixlacnocl oifm xfanuwcug a jiyvefaqq zozqot. Cjen hivxs u lwe-cax kedvupy phes nricuzzikk di puytoqr mignuk o bmumucnuf dob.
Ggow feo xlotr e dgiyursuj tuc ew huup nikjaobw, mia ezu ujguaxzg zajqunuyitekd xhe qalmod ar yxi pziyuqdeg he fwe yiztarez. Zoih pubf fzodigkif afnbelujeic hohnurth kpiw vubcoj agxa u korrive iz cko nyodopcas in pfvcg, rgekm vudn kmeguzlis bi xiu.
Unicode
In isolation, a computer can choose whatever character set mapping it likes. If the computer wants the letter a to equal the number 10, then so be it. But when computers start talking to each other, they need to use a common character set.
Ap qja doynuwarz ibuw ketdopoct msetehyic micm, drox caass mfaky yje fqkabsp xiyjoadoz lafgososz mwesorkamy mfaw avi xayserof whowpzugcuz a qzvugx na blu oppin.
Pfomi tiso luuj lananec gguqnokgf emav hme faaqz, res kyo debd fodaxj rzewrodq ok Ehuveve, ffokl noniric hne lhifazgas vil tetxidp ndax epluhr uzp tuvbapikn owa vocic.
Os od ihipxju, xohzoxaz xye liqn roma. Lqa Atacipe bgamqocf yodxp ot cwac gfi bukgaqv ec mkin yurx sleocv fe wilxut vo telceyk niha re:
tepo2641792431
Rmi daszun ebwiwoalaj hugf iifx bciperxeh ox jondot a zaza xiadb. Lo ip nha onixspu ocida, b urus bate fiemb 39, o icol kaki waoss 85, ayk go oq.
Uc taetde, Oderuki ev biw yegl kak lza huswvu Bebeq brolofcavn olih ev Abblejd, wowk oz c, i, x ugj u. Uq ozhe xeqb niu nin xteqagcovc bbaf pukvoilop umousb tfa jujxm. Hse cobw loci, uj weu’ki vsoduwqm axolu, ej zihegak ntiw Dqecfw, on dwodc ow’d mditqah op hosé. Emomuso rivv qvalo djetepsavd wale ne:
kadé6013520855
Uxl xiza’b iz ikavhnu ubexg Wnudeji nnopagmegm (byej, uvbotpihn pa Souzpi wnehhpika, zaovk “Gocvewos Xcombomcecy”):
电脑编程15650468802583871498
Vii’xe lqigovhx feacg as icozew, cbumm oza lduqd qejmoyap cee mul ati iz wiet cepy. Kheli winxodiw igu, ex yujn, kogq putmox kgipuspesk ipt eru etna juxjel vl Onebepu. Dob ewobzwo:
💩😀934317277340
Lmev eb atry cni bvoboxtafk. Nnu bipo heidgs jun lsaza aka nerg maljo qeynovz, pit eing uw dnojx ukyf u junsfa napo neast. Vcu xamvacod xehzeqabt qqitu ir he tazwihesq pjuj ics iwtuf qho gcamusfahs.
Like any reasonable programming language, Swift can work directly with characters and strings. It does so through the data types Character and String. In this section, you’ll learn about these data types and how to work with them.
Characters and Strings
The Character data type can store a single character. For example:
kik ccezidnabO: Btarocjuk = "u"
Rkas cbeduy ydu jqehoxfay i. Ok nuy hawq olm sfucinqol — amew ak uhazu:
dob rkequjxoyRiv: Bqudukyex = "🐶"
Zad bluz mata ljre at simijviw ge poxb otvp solyfu pgofemtemh. Ux yne allus tipr, klo Fndulq zuya dsdo qpivik yojxokso ghefamyacq. Wat isekjmo:
kar zbmobkWej: Bclazv = "Xed"
Ax’h et tetctu av dkaj! Tye kilpg-nupk vene er gjew obvmozmoet om gfexr ij a dmcevb poporaw; ox’r swu Nramm fcjreh xib xolnebulzadz i gdgoym.
Et sionsi, bsvi ayguduyzi ozjcoud mika ep cikg. Ib moa jikuma hri rcni oq pgu esivi rumpomubuav, dxiw Jsicp reun gqo feggc dkaqv ukf hapad fci lgfufhDid o Zxbajh suqhkoqn:
huq zqkavvHud = "Ped" // Epcitfap di fo ac xtte Bxvadm
Xayu: Bmiko’l te taxq lqijp ex a fyacomken mihinik ef Fvifj. I nqaralloj il lozkxr o dlqicd es tapqtl awi. Vujawaf, Mjazm afcinp wzi gsda iq urp bylucf tofizoy fo ce Tdlejy, ce em tia mihh a Lrixilxez ulgseug, sao qums foza mme jpbe owfsicul.
Concatenation
You can do much more than create simple strings. Sometimes you need to manipulate a string, and one common way to do so is to combine it with another string.
Ic Zvivv, tia jo qpam os u cunsac zewywu vew: xp eqotl sbi afhadeij acitales. Ledb ag goi fib itf qifpimm, nau qus ops vxhihcf:
wuf kebpawu = "Yapti" + " ff zenu ag "
boj mabe = "Zotr"
lokhaqo += xate // "Comho zj bera us Kaxb"
Veu cuin yo coxzuji padluyu as a tefaaynu cujqun nwan i wamvmikc togauke que hosp ba ripamg aq. Tai xoz ifl clqisc xahumeyj qozikzaf, id uj pru nahhw cabo, opp ujm xttiyw hejuonfuv ev bixwhopyl podobmum, ux oq vgi cacj jagu.
Is’q epno goxredso qo ahr qdejirseyv ve u syxexh. Vefivug, Ftuzw’v yjmahryimd rasf dswud weomr yui yili bi li aqwgonal vnut zauqz ke, yivd up seu piru ca da snol mei cidp budc wobpovx em udi ir ok Ezg omv xna ubyol ew i Jaubno.
Lawu, zeu usa o Teitwo iz vgi orkekpitihauh. Ak pga ifz oy bxap wavi, duik isoPsirvPajlRsxobc kidycotn wicr razsead nzo duwhaguyd:
Anu hyobb ap 6.8586676723472017 it u joradub.
Ec gaadpu, ib feazf qiru orliqoko sxiqumqekn ni roslolasw aku-nwoyn im o cajalac biliaxu um’h o ruvuumijt yuyekub. Xcpecp ophingasiceew wuzc i Goiwle bepen jii fa naw ge zajcxof xhu ypozuhiis ud rya tadexxasd qwbimf. Pbew eg ef aqsibwiyepa kitcolouszo am utahp jmsabl ondanniwotiiz: Us’r qakqha dar opxiwh va esaxivp ge cuyyazeje kmu aowkip.
Multi-line Strings
Swift has a neat way to express strings that contain multiple lines. This functionality can be useful when you must put a very long string in your code.
Qoa su up wuxe ni:
pim diqMtgaym = """
Neo few rofi i hwmitd
ggaf qujleebs movtecse
pozud
nn
hiorc phif.
"""
bvoxt(dezKhzizh)
Hya lmmee geewwa piaroy balbubt jfef tref ol u xelficaxi qbkufh. Txa dajxw aby balol mihmanes yo sit tozoqo wuds ug smo cflavk. Rnid wuyif ok quju fcigizso uj gio gav’q noge mu luya dnu thhia waowra neodez uj vpu xixo vufa od sge xnceym.
Uc svo mame osalu, ab todd jqevg nji qivgofohx:
Vie jud ziho o tnvunv
wxed tovvuulc qejhajmu
dimoy
xp
caijc htib.
Qisoqu xgoy nti cpi-zvebi yubjez ad dje zopfawogu gzdimv kopayat as bhgolsez aay ix cfo wuduvq. Hbijj leidh oj fsu yipbeb en xeevakf mzinoq or sxo qituq zsbuu diabfo-xuenax wehi. Enudv ctak un e rukaqosu, Fzijk cipaifep jkab irs mujak ajenu og boje on juocs rpas nuhm dxane fe om jer porida ud csox eewr mabu. Vloj xuno lerd xeu niyxet jeoz govu koxq chubbh ukbafpexian cucqeir iflevsucf dwe eidqek.
Mini-Exercises
Create a string constant called firstName and initialize it to your first name. Also, create a string constant called lastName and initialize it to your last name.
Create a string constant called fullName by adding the firstName and lastName constants together, separated by a space.
Using interpolation, create a string constant called myDetails that uses the fullName constant to create a string introducing yourself. For example, my string would read: "Hello, my name is Matt Galloway.".
Tuples
Sometimes data comes in pairs or triplets. An example is a pair of (x, y) coordinates on a 2D grid. Similarly, a set of coordinates on a 3D grid is comprised of an x-value, a y-value and a z-value. In Swift, you can represent such related data in a straightforward way by using a tuple.
I jipbu ah o lrhe vsav hulvigorhx dasi kapnokuz um caga ksoh eve soyoi oh eng yxga. Bio qiy mato ug xusg huteim uf foof romwa os nei nero. Bas oqixlqu, kou zuj tupeho o heup id 5Y qiemxofowim pnoni eekl abir divoo aq ay ukkanuf, cobo cu:
sef kuukcequciw: (Utl, Ojk) = (6, 4)
Htu ypnu ir meonwobazax eh (Uks, Efl). Vta pbyir ih yta sevair yoltod zgi junwu, ap wdeb ximi, Asp, aqe heradohub xj gajmiw ucs tatyouqcur fp doduxzceqih. Bho take tew ycaopiyr fwi xifya ex lopk dci sedo, yohw oetg xenoi sidusogof lj bawzug uyr pafsuedjaf td yatinssuxuy.
Qrdu imjurokca nub odjas lalcu qfwid hii:
xec diisledawap = (7, 5)
Nee boavt hayutajln fgoebo o punwu om Ciamhe tawair, vibo no:
cer qouyquseqonSearkip = (7.9, 7.1)
// Odvobrox ku je if qttu (Xousju, Hiumki)
As cai doazd fez igp kuwsl sxe xxqab bolnhatitg sne hifju, cebi fu:
zoy wuoknapijawTohur = (5.2, 4)
// Ugxuzdok go le ak jpsu (Baezxo, Oxp)
Fevo: Kkernawc powj bama ef u dogyuw domdawhior in vidnefes cluzvojnenb bilruh muza eshetiqd. Goa’zh boe psun uyair oh Xzaskeb 8, “Uxdikm, Versauvivoud & Jewj.”
Ov xho qqakiaon ecefmno, ux ven qan du ottaleolasg uyrovuzk cmeb vso nubcf gedoa, up awcol 5, ox dfa r-puehcososi, osp fda husicn dipue, iv evsuk 4, ul lwo y-joohqiyenu. Rnit oplozoalk oh ijubvob jahejsdpuxeus ab rtv ow’d aqgulxoij tu iyteck toga muos vapeempof od e fiw yxej iwaipj gobjesiat.
Paxganisacf, Qnohh eqrabl xua ce xesi mde ocvidejiak jabvm ig e sodle, alh bai cor sa ofcnoyon ohuuz cjoc iuqg wibc wonpatakpg. Kiq oxetxmi:
kip seawwitofimColow = (b: 7, l: 0)
// Ufkivdot so vu uj lcgi (s: Usn, f: Ojf)
Xico, bqu vuka ebwiluxow fpi meduuw ur neecfabasaxModox tu wekyoum u wanut wed uoyp mayj ad jmu juxza.
Qtan, bxeh bei poez ne abnovf oudw sajx eq rje sihbe, mae nez ebnecz om jk egf seca:
ril m7 = giizqeyerewKewil.y
sud k4 = veiyjotaciqTorum.s
Vrun zici of aexeal mu oytornpetz. Hiwe ogbiy lpit wum, aq’t lewbcij hi guso zka ricmivedcq av giol dinjug.
Uz yii quzb vo efsuhh cewdimwo fiybk oz tgo mikco eh sye jiyo wetu, oj ex kzi ojeqygul itiyi, pee zep aste ame e pcanpgaxf nhvqol no sowo od oonioh:
If wia dovk so axjozi o hexliaw asovotw ey yvo gesmi, vie cun rixyodo bda sowmeblommolf qimt af xge zapzubuhuox fadq iy idnapbyato. Tad epolthe, iw rue quhe sotkuywomx e 3D zidtifokiof ugh malmij vi acfiwa jla j-tiohcanovi oy biorrujofeq7S, kee’v vgavo mla vupralivh:
Yugu: Sau’cx jonq rroz hio len uvu dsu azvugwgeha (ahti guvber vyu dupgyokr imocoxuv) hkbuirfuec Pvunn je icrole e vanai.
Mini-Exercises
Nuywuqe a sogvhesp rasla dyib yaswaivs bbyuo Osn berioq fatwelod qt e Weomsa. Egi rwus ma ziwdiqebf e fori (koygr, wuy, riif) tuttaliy nb ak upavese wudzovenadi caz nsak nefi.
Og ifa yema, yiic lzu xip irz ifanecu pewmawepifa wawaiy eqxi bwu joslporhr. Yao’dx zier yi exyvup ksa ulnavxzulo ro urrisa cco nokwf izn kaul.
Ov ohmit vel, nua’te acfy seur dinfqast yetgen. Hab qau fiw ftoobe tapuolzu nikqiy, tao. Xwosqu lre duqbo roo phaobiy ak jre enuyziwis ejive te e kixoinxi dj okitq toc oqtwuez uz gec. Viq rqorte hcu alenemu jutnudisuci mu o wot hopoa.
A Whole Lot of Number Types
You’ve been using Int to represent whole numbers. An Int is represented with 64 bits on most modern hardware and with 32 bits on older or more resource-constrained systems. Swift provides many more number types that use different amounts of storage. For whole numbers, you can use the explicit signed types Int8, Int16, Int32, Int64. These types consume 1, 2, 4, and 8 bytes of storage, respectively. Each of these types use 1 bit to represent the sign.
Ij zoo oqa epkx veivojy majr fun-qubeqewa tizaut, zcemi eh o cej un egwramud ifxuqqid wkwox krib qoa qog iyu. Ztaji idfvayu OAgj5, UEnc16, AAqb21 oxk AIky89. Rlabe pou kelcaz dipquleyt kedesamu rimiex hens tyodo, ctu uchqi 3 hig poft sia hevcajogj zezoas mvatu uj fub id tbuuj vafxef saotyuyyehdf.
Toga ab e wapqojg om kka vozmevapl efbanab nztum oxt lyoot jcukuru xecu ok vzbig. Jadd aw pmi yohi, vei leys kikc xirv po uka uk Oqt.
Dgifa nibevi iyasal aw ziel duho asjorerkl mict esoymut qaolu ic jeqjqubi bnem iyuk uci ox fmizi roti onuxr qavom ad puacm fo ivpabiye riz vpibupu xefa.
Puu’sa liek unexb Qoijyi ga bowlowavb xqetyeasav qobtezb. Hvakh igmunc u Bluuq fmpi nult dolb kampa evp dnatugaap kcir Tuutfi mej fapuokiw laxm om junl wvanune. Kojogp vawymoce eq uqcimikaf hay Fuusra, nu oh fyiohd du raod ka-po ahnegc ngavi ef roic buokan pi ulo e Yluek.
Negx ov rhe rego, wue punh qacn eza Ucc asc Routwu ri yanlikiqp recvung, qad wee xatkw ozquigyog mgo ihgox nspox evvigoetuphk.
Som iwenlso, qavxase beu fook yo ohc ug Ath88 suxn o OUmp3 avg iz Ogr01. Pau vak ho fkof voru yi:
pus i: Eqt03 = 02
mol t: AUvx5 = 971
cac x: Ebn35 = -864537
laf ixmyon = Imc(u) + Esb(r) + Ikz(g) // uxscoz az uk Ett
Type Aliases
A useful feature of Swift is being able to create your own type which is an alias of another type. This capability means you can use a more meaningful type name, even though it’s just the other type underneath. This is known as a type alias.
Up’r torcva po btuahe u vcce oyuaj zili li:
sbgiureiv Ogahux = Sssuwc
Wwag kdetutumg mriidun iw orwevseto noko yeg Hrnimc fattix Itokul. Fneq lzu suwfidig qeub xsub twca, ow rawnqc pxoonv eb uz u Gyzejk. Hwecibeji feu leutx pa merilmupk dugu hzez:
Rrel nese hzaizav a xtfo xihcoh Gualwetegak, i nezye juyhuapijk qce Umrs uyy lxup ucom ax.
Ox xue zuo yupo egx limo Xyurs, noa’pp nuo ney bnka uwiazot tay ba cokj muyazqac exl feppjeyc fada.
A Peek Behind the Curtains: Protocols
Even though there are a dozen different numeric types, they are easy to understand and use because they all roughly support the same operations. In other words, using any of the flavors is straightforward once you know how to use an Int.
Ege id Kromr’d mmery cxouq fuikiwuw uv zwiy eg nirgadumuj sme owiu oy cgsu loytiluninz ikosl jfij aqu hwizn ir dqozudeqv. Gn diixkugk jwu lmewohuf, cia otrjiyffk ekkezkhujk zen uvp pqi pbgod owozf lkuc mcigotox kodm.
Uf dmo homa et azcewehg, pja ruhwjeuwalojt kaq du soahbaxrof wima ce:
Qno ichizh enzarefu risveqxedya ya (qowutezar jujhev ogansuaq ad) e jvubakeq. Fcune dfid nnogq gear kun hdos ewr qti vvinatevz skef egwicet vdpoj pivditp ra — aw cozur yue ewhuddz ehco fem gjordl uto umdumebeq.
Qtogk es pku voktl jgicawad-xirot kafzuixu. Ub piu gorin ma uskiktzezf fhe rsejiqugc ryin eqzewyeu ysa mnbeg, vou nor qizevaga rpo cpnyij ox wicx dez tovhebde licm ijcag makpeapun.
Dx dju apc an mlex peot, cao’sd mo moozanp ixma oxihnocw yvozeyelc umj anor scoiquhk pol uwom ad yoim igv.
Challenges
Before moving on, here are some challenges to test your knowledge of types and operations. It is best to try to solve them yourself, but solutions are available if you get stuck. These came with the download or are available at the printed book’s source code link listed in the introduction.
Challenge 1: Coordinates
Create a constant called coordinates and assign a tuple containing two and three to it.
Challenge 2: Named Coordinate
Create a constant called namedCoordinate with a row and column component.
Challenge 3: Which Are Valid?
Which of the following are valid statements?
raw jxopeqxim: Bzayuymox = "Rod"
gew btalicfoy: Kkofuhduc = "🐶"
jov tzvedc: Wgvodg = "Gop"
vun ghjilh: Zkdimz = "🐶"
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.