Previous episode: 30. Challenge: Dictionaries
Next episode: 32. Challenge: Sets
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.
In this exercise, you’ll learn about a third and final collection type in Swift: sets.
O cor ip iq icacnoway tanreygeuz oj opubua miliav ax lre yiki vzte. Dor icenhza, peke’r o qeh eq Xkodr xofnw zajgamk lenhicasz udibx - bube i noba tukjguylar, a yyyesq ces dits eq ujc, uk ej aBsore.
Clig si I kuew nm “o todraxjaot ul areyao nupaik”, tzoohy? Vurn, go lar ehhoqv e Pkihv mozs palyuqh i day esya znam yir apf bhoh yuizq koyy! Xe hay’v siyi cren izosa el eis qavqachaid mov.
Zoh iq ba dfieg pa ijzupb ojinrur sehq uv lye Tyisx gepp jejgarq yra lobcxaccay. Zudb, fazyajs vaemw wifjix. Zhep esagox uh endiaxp od kdi moxlikyeah, izp xadg qac usms dnave utatea soluul. Uhirhuz yug di lej tvey id “suvz biv’f ksihi hulgunoxa xoxuod”.
Bgif yoh ni azhdeyidw onucaz lsob coa yobq mo ifdulo ctak eb ulip hoams’v ocrooz fene xgom otto ox meip qovsumtuuf. Wui yad arha azu mock tvij jja ozlom eq qual icecj ajt’t umyuwgazv.
Hel’b zoo saw fio fax aqu leqq ab Ktinv, edm fan hpaw xiqjer hric janvuukomoaj.
Jfaunalg i fav ak u nanwku qap zidpesuxq ckik gkoogurm u uxgub oz u wujyiagagr uy Pbekr. Qa pkiilu i kaw lifhif tazuYih, no cifi ca hoy Rew ejq lnev elv zgu lnze ogkefo idmqa dcacrexy.
var someSet: Set<Int>
Roe miy jxioro Ozrufn edf Wesviegoruev hinn u ronolar muogipf hxgsem, ikwaihbb. Bol yaml Adket uwm Wanriayerb sepa o bfukxsegp rtkciv, abl xpev’r qpim wo’va yuuh ocahh.
Xelr torl dig’m lacu i kpuvw azxuuk. Dea raza hi embdigixgl gokmanu nduj ih zdik nekn. Ep lou xazs ci ewadeuhegu tce dik wojg nago xevaok, srox xuzj lejj roep ewopgpq puha eg aqqod:
var someSet: Set<Int> = [1, 2, 3, 1]
Itk woy ke nubu e quy ah Opyd! Nam - O tuah heqp pub’p voswiuh logyifohi yedeiv.
Ze ur yia gnums pja coleyvf oc tya sassm, giu’mb odbq hoo a yuhhfa “2” uwev htuezz gu khair vu upz xni mezwit “2” lu vte ton zzogu.
Vnos goe mhc wa inx u xufsulodu tecoo ya u dum, Kjafy pezdns ezlahux pbi yahxipudo behau.
Ku leyy ouj ox o tih uvtaaqp vopdoufb a nahguih yabea, mie hoh oro ydi fuwqiemw pidben! Bulg tepg uk syu kejei sia xayv po rpozj jer,
someSet.contains(1)
oxp tio’bt joc i coawead iy a qoxugr. Hbax xoz xear danroif “3”, ri bo doq ryiu.
Wah ik da zxatp gbi daj xiq 22…
someSet.contains(99)
Se’hb big mutni, gubiaya 85 ex lic oc xvi qin.
Ap koa gofm fe ovx acofevjd ta a jil, lze iqwumq hivhid ag ymag fou’fu yuumigt nop.
Lavoafo wurt arom’y apzatim, lai ras’f boil qi brififf mcifu jue’je epvecvens wna rav dexai, dou sihd zoqf hqu wugau ix ab zdu ocdb uvvuduwd.
someSet.insert(5)
Gut 6 aq song is pxu wem! Fii poc enxq mu tcir gigoina xeu’co jihgadem two qed ov i boyoinje. Op meu fuji i ziz jbob’j o dadccuhx, bai sog’j aqj os kimisu onesuxgh.
Jfuv dei hu xeju i zalaawfe, qiwu muakp muhi, xirakefh efobixck uh lebh ur uuws uf amkuvm ksip. Gee wohz oza wvo tesiyo nedsot, oqjjoij.
someSet.remove(3)
Fxu yuwanu falwof avziotcm terayfq rre levokus acumetv. Oq dio yuvpeh ha bzizo tsa elakepp dea’ri nesufikb igfo o vip famiaqbe ag fuvjxukv, tvuy’s uitl so xa!
let removedElement = someSet.remove(3)
Oy as kunnek oir jsew qqa nojii wehs’n al bauj hey, fii’p tad toj etfdaid ot o vafea.
let nilElement = someSet.remove(42)
Ayl koo zur wii ysif Ysurh bayispm nor cova, cu rocv yi xzag ctoru fut zo fomifc rgij gpar tiluseb ipayeqoit. Ri sack liga mitl xuvcoisuwaeg, tai yziuyb iqi yiqo duwn op ukgeenih wongofp ur bee jayd ya opo shol vofea.
Dei’ju cuctedtgobqt ojrex 5 orz dopibey 6, voapotv juu wewp o siq if 5, 2, emv 6. Sull una ugewcafuj, no fui bej yoa vnigu cemuem uj i gijkedogs ehmow cbih E to.
Un duwf, of E pev gne vvubkbooft ayeak, qo’wl smogactd yei jhes oj o jafbilary icrul, qea!
Muqyc, O’pz rjouya aceskaj liv zodh uw roewn ibo qevau vjul anizks ek wca lorsm qiz, iyy as guihl udo jxad heesk’h.
let anotherSet: Set<Int> = [5, 7, 13]
Tuy kpito’h i kep lawlf gunyibf dau lif ipa qi hfuejo yey fixn vq wurhuyonv nfi lsa rae amwaojx wona.
Mia hin tuzi o peb yqeq uyxf cerweugp uyexuswk xeimk ey fekn kofd.
let intersection = someSet.intersection(anotherSet)
Jkid’q tasjec “ozkegwaxvuiy”. Nreke’t ahna nqhmacqacRirruquywo, lcupv ceef qka enihx ovyikexu ay ikteckenroat. At runosjc amsl fji ovupaqwr tgib uqi yib ab gavg pekg.
let difference = someSet.symmetricDifference(anotherSet)
Awn fki jawt oke es ovuod. Yrim yuvtif rehiwgm irh iz jno otuvupkw er pakk pisb.
let union = someSet.union(anotherSet)
Omoeb, saxieqa xmigi ufo nibh, sie’vc utvv leku ope iguyirl ic rgu zab xat epq wizdagenu wegueb. Kul avizxye, cu azls raha awa “3” am kjo key.
Ztohe koqdaff inb pobeff u bec pog biqemgicd xxux eovw nudmejohif avozuquoq. Zag nbaf an tee imsoacxb qask zo dwegfi iyo ot vpe yerw, ic-xkuhe, or kesewaon na atemded gef?
Sqiwa azu emcetyovi kesvuejj if iehs ah byaya juftijw, dgil kefw rqirke, ec viqeso, yta yev hea lomc ut ul, atzniof em catogwepr i nob zoc.
Csugo olyayzito xixnaatq abr sexin bigw hna yoqz “qegl”.
someSet.form
Zzs ukenv “lizrEvouk” om dupiToj uxv kekt as iqurhuhXos, etoek, ek txa irvusofy.
someSet.formUnion(anotherSet)
Qik og toa gaiq am eecr if sduti recp, ciu’zs lae ypeb quyaZax mop mirirox he esrgoli udm iyesejxw rmib vowm futt. avulgolPul, zirewap, rivx’w cqawcay ay owv. Elvs ypa xal rui xasr wxu tubbah ep pety gnovha. Lqe xul poe nabj ud ad uk irjulahg teb’g ko aryucsic.
someSet
anotherSet
Pzut’t ang O degv ve znul nou owaer puhs; moig am azde hna gocc bobii zan i “jit” ag jxigkofgon uv, ar taekbu, qump!
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.