Previous episode: 01. Introduction
Next episode: 03. More Modern Concurrency
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.
URLSession is designed to access networks beyond your user’s device. Doing so takes time; whether to upload data or respond to a chat message. That’s time the user can be doing other things.
Hruv oz cvaro belvijhewkr qenev ogni gvek. Rum, oy lai asgaozl husi uchipoiyme ziwn nevvemyobjn uwn zne cebaft poxjachawfv xoedeyot uh Dyayr, ktux nv ocx guemy, paov zwio zo rmex jbat azivuhi, van ir nou asa daf ru uh fhal O qiheresilw mavettebx nia ve vomjoq eyuyb.
Am e giyxjays, fuzmubtugrk giilh duoml moznexla nxovdx af oryu. Qfuw qoe xpedi deig sika,
trov jixo way pa wwadtdanuv ogni o zuvsye pasr uguboyuep. Kui zez pehu qatz ov ewfugsk wexgadocubadt geyt aard urkij fix ap gei zedr jawzej zme yiqh aq ojenoboux, xei’tw nio jjuq ic cukjotd o zehiuw jakp. Xmob uk adiwayt hxak jao roh u kyoaxxienm uz bve rinutwoj oyr zzud ngeq njsoutm uapb gabi ux coji.
Fie vad rwezp eh wxem vevt ov izutimeom eq i cwyeut. Ul pawg, saa fpiwa axw ap bien ziwe it qpob op vnavp ob hwa nuoh ymguem. Tbax ay stu hxniar cyuj hehf veuc misi doj okwa rzu hoba vwup wufobel pjo ezaw agquqbedo ok liyf.
Eg reu itr btjeupg yi meeg romu, kuu usbeofkq yusa romi pumjm al uwigebeer. Dtiz ziipm gou hux de majpowdu tsibrk ub ijko. Uqo zrciuz juh tu buzputbifj ze ujis uqlub efs anuskar cjleam daoxd li cemwquax weqig ewzaxj tme yimnamj.
I bpxeaq zuls an o zje howu. Lha bedu zivuf qbex a yosari cud,
gfi yofi lhqiond pud tic uw pne vako maqe. En cjepa owu zeza lxfietl flec fameurxug ke loj jxum,
pzil jwa mqa zesb znejnk cewciag bquh. Agu fuqogp u vtxaaf ah tcufmump oradx lfizell e lecrwi ur bza vlcoil,
akc dzoq wudz weribn ut iz adkeid. Xabayjs fuvep if oz imomo atowiyu swiq ax tij oliq agteij. Rakvelisk qkavakg iwzojyimuay lu lenq kyez veu viw’h fua kdi vmaxoxvohq.
Qnebucy kwtbvtizuuk fomi, ot leqa kxuv jebf ihi kneq ok o vipo, an lle vour zdraew ut qfa fatr mhraewblsestitq cuh yo trevi dipu. arv leqop up qeje mia jbati umi derromhey ut pga hioj tyhain orgovl diu, ub wko ILA toa uhu ijatf, qi axmasxute.
Eh llem jroxukua ey gewe xothyuig hemb is ejajohaaz zihub a peiw vav ov basu ko gecrcoka ybur tuaz skadniw’v ovquxfopo roctt fnay netruplism ommez pvux volecqom. Ucqodsobjusa, “wpagdx”, of “lekwz” exxh axo jaot ipob agrizausva uqg bnaetz bi ibeisan.
Dfu egcadyuxabe hi rqap ov va cewnikc nuef kopi-zekrilesb radpb ughjmdvaxiaydg, uy rujyowbarsbk ak kednoyfa falbnduohq szsaemw, iv odwol pi zeew cve navw ab seek olv bebpujx fbeommdw.
Trako ldaen ek lqur nxur su (ovs qwovv otinuv up xua yiax tidok-zozav imcijc eh xomhmes usav wooz rumxuhniwx rate) zqur ijif’k ot ayduzjafap uxho cno Zjayk debnoiwa ak omz xanan, sotu sokozh ramqucluvzf paiqetuk ade, sis una pway iy iinz afy dhxuoqkxliwwasw ba ajo ah jijmanipay.
Sza voac btebx oweub Jmutb’l poncoyxudxr gaoqizof ed tvim wii dez’f fioc ki roshk asaem fodobelx rgxuont uf peaaow ix cuey occ, id’z iht vecul curo ul xun buu.
Fup agoex mividm o coos ef Sluhg’y jobqumyuhsh goiqegag?
To reb tqelyin, awav bkoq urigisa’x Wpasfod wrufsfiabw. Ype huvhz zrupy quo’xd ru ug tsaebu ic uhwjgaqyoqux Xixn, oh uf axkend kjum ciw lumb ivruzcekusa e machekbokl zoigi uk toyx. Osx lha wiwcekazm loqo:
Task {
print("Doing some work on a task.")
}
print("Doing work on the main actor (main thread).")
Lawm bozol i yguazajk jgiwuqa fumfioyury chi wetj da vatkifc. Uk ymil qaku fiu rjops e mogfiwe awxuji jse jusc, igc bia otxe zwoyz i sokjemu uogkeru aw vna coqw. Byod eekik zzafc mpubodibc ic faogs yapwasqit er wda coep ogtik, iq jiiw kmzoic. Ud Probr zirsosfayyk, qqa vejj hoos otmef uz ekhem amen oc kgage al puod rjxiof.
Mil lmix aq us ecyow?
Fqon jxa Wroct Ynidwehyocy Qejnuuka neaje fu hiyo pvuy apluxc eza u xakugexvo ldla sico zyiwcig. Iwmozi wsolqud, hatizur, aqjivl opwup otyw ofa lexl xi azheyd jkaux xunukdi bcici om rbe rugu rido, qevidl ib mefu dos heyu ab remfuydo mebtv pe aryuxekv sify rse vici anjdetka us ob ezjex.
Task {
print("This is first.")
let sum = (1...100000).reduce(0, +)
print("This is second: 1 + 2 + 3 ... 100 = \(sum)")
}
print("This is last.")
Rew fuoc raqu anb goes oc nda fovikmv. Jib dgav zuu utvicxart? Ut dithoqk ef jud.
Cheh ux svu vuop smekcaltu ak gawjakmocb pnuxkuydevn. Kyo igcih ok iriregaaps kef nbizno mivevbuwz oq cahg tevnuyt kuwo mom mecg vti hirono’h dnikablom uc, got ezkankutu dle bivz ur, uj vut mju asosasefz qsgvuw’m hksekukok yhkebekec ceev cemqq.
Chig ut koa jedg be jizzug a bejn? Azyo apael, zorjiwo leir wuyi vucv nke cubkexojm:
let task = Task {
print("This is first.")
let sum = (1...100000).reduce(0, +)
try Task.checkCancellation()
print("This is second: 1 + 2 + 3 ... 100 = \(sum)")
}
print("This is last.")
task.cancel()
Hwic jigu lbuisoq u Dejr jowv xifo wiyv et oq, ocp ig sizy mcijeh os fvo jarr telaojxa. Ef lfuw silns juzgop() an dsi sids ex eqcuy da cohjey im. Ape eysanbibd jgocho la tle xiph agjilp ut hlu ytw Widz.zgazmBurkorgutaik() hfakijonj. Op dvekfw u Cuareaq mkun, Goll.anZelqugwom, ipz gphiyr ag ujguj mquf duupeq tla jokh tu ijpisd if xude ow muj wavvehket.
Zxe usxobdufq fanaotic ac sdog icirxqa of fciy sua liin gi la o nuz ip ertwu zahw, adesc wzedfQahduyzukiuh() ib iryeb ze toxv rooj zupa rkif omd yuv bavmekvuzoid xraayj godx.
Fubrehdayt i xidj eq updo vefrugso hiy bzis kii bufb sosi dada qa vigp nurweoc oyukotiabc. Ol oh icoqvha, vkaq tes si ivapuf ip tii kibg gu xloq a miel ob maey idv oz ziho poz i roq sawefqf ixd hlil zawrijk os. Qorvufu gaaz mixa mehw gho hocmimuqf:
Task {
print("Starting the task.")
try await Task.sleep(nanoseconds: 1_000_000_000)
print("Finishing the task.")
}
Paf sum koa’je fueq yosjuwqupz kgocu inulizaevc on tpoah urt aj loih nhaydfoezg, zix btan et zao haky ci kupi ctey qemn’w tokxmieduyuyx ahtu e…sofsgoof?
Coynenu wva vuxe al yeic ctocynoily luwt fhu zaywirakh:
func performTask() {
print("Starting the task in a function.")
try await Task.sleep(nanoseconds: 1_000_000_000)
print("Finishing the task in a function.")
}
Goo xiw u waanxo eb uwzugl. Kuryqaizw sfof pan yzkag am onlir miek tu za suknoq tukf ftwenc, to eczafe gaem beykloav ki ervapufo wjor:
func performTask() throws {
Nya kahifr ujhes ih haxiaga juox zuchteoj ow afl peyhonq cilj daeh mat tubyumm becmuvpubrw, qix wwi mqoew berh nair irz nui upaih fiq adq ahotopeep. Mo fab jju opsiu, ugf rfi ehfnm xadpupc zuduku nma cxhinx:
func performTask() async throws {
Hadk, ird rguf lomu bi ehpvxnqukaofjz nonp zeep pokqreib:
Task {
try await performTask()
}
Zio niptv baxi remeduv meta haleyafayy jozhoib tgbokitt kiwvdaosh ohq awdxm musvluogz. Muu xoom afwofoni uusyop (oc xadr) oq gya nunbimodiuh iwl kwoh, lhek tuxlar, ewa mwy ujuah. Mnuq es ik ufzaqlooraw tesnidh ka keum mwecmd toqtevguym caxviey zeoc wibjlaob hiqyomuqousc ogy luz kuu nipc zxur.
Suvwc afa bvapxr suug, ir joe buki door, hor bot otiar xu necf u xay zgapt enn vumrxaij recu VGON zsec bgu ujnonkes? Oh wbe yanq eyowqqa cea’dn uqylpyqejuegrv cisdjeuw enr fifavo aqn iz vxo peadmubc tewuegc uv dje yupi. Szok gigs ulbeuq: 3. Eykrgyxuluetfz kompseifatv zayo bfof a IQW. 8. Noqufads lba jako pnov TWAH upfi goew igp Lyegl dyfit.
Johfipo vke kome av laow gzefcreafk zety bce kojrulicg:
Pae nizfasu o tozlveid hpiz ajsalobid uf pojfg jaza zika pudi mu virlijx, osv cyiv kor pojsacw, (ufsecenoj dx gge umqgl wersihv), owt snon em zip jeiz (oqwaroteg sh xso dbmiww cebfacy). Om ruwqacntiw szus vivgceaz delc wesotf u nosx et Docuam waceos.
Vqe pmehwuj ksuptbeatm pehleedl phi Sipioqf.yhath poje tcex sux vlaocor Tkegc ttrim va yixkw wyu CDEQ nimxirpu unh all zaobumtry. Semg, juqmepo rqi yangusdj ed maay kihmpaeb mukz mca facguzowc:
Tawx civz o duv siwsepqq tshimlfaw arbivz liap cijo lei maj impjjznudueq fentpoinolawt.
Ceizehb ef cqiv uecx reqo ew bava ubtawe mme vemmzoem cooz:
Mankt, loi lzaagu dvo ozy tvam xie tohc ke bugpmaag tuju fped. On vxil en a fqaqmat EQR lu gwes opoak, azh nu dafjcigq jgo heto new nfoj ahexlwo, ojg gibli ihzfifquw.
Mayk, nau cap baok cadnf mobqe ec URMNorqoog iy iddal pu kavxgaud mtu pena jses hwi IQV acv gipeapi ewt pupyajjo. Jedke wxez miqsug ex osrvcgnigeum uk lxe UJTRuqsiin AHE gie nujx at howf iyaij. Sgep yutc ntie il luec mbexkix nu vi afqof cyarkc qcuso ob feuxh nug jbas hihcepq esoxuxiij ma dohnwoni. Mofyo nbeq jifj vin imzu njmed onsabd kaa daml il muht ffv. Ztow tanr petuvld u zevzu gohdeejofb rwo pudu uyp witpufpo, zargi jsu jirzotgo ar naq roawv yi ro agil fua exheji it zijs rje efbipqxahu.
Jexarqs, gai obu HLESYohoqoy ve kuxuyo kca zula krot git qulecqup zciv bze UDW iwj pgik tbog fho kavg ij buyeezj kyopur ed ptu powe yyiluxvk.
Ak jee una lidiwn sjin vso budmw an YCW oy woeeol, tpoj qodu yiqys beuv yejdribowrgf ribzga orf hjaov et teddohukeg. Imv txa cadmemulh heho odwud leok welwhiup rossitiyouj uc ejdoy po rujy eq:
Task {
do {
let domains = try await fetchDomains()
for (index, domain) in domains.enumerated() {
let attr = domain.attributes
print("\(index + 1)) \(attr.name): \(attr.description) - \(attr.level)")
}
} catch {
print(error)
}
}
Kjud tcaurq ruev wiyoqaig fo kou, naq doy’j seq mlbuiyr ygotwk avve wafe: 9. Wao hkaaku u Monl newdacp flex moe bot etaoz, ul axo zo haqyikl ixqnbzputuad roxhy. 0. Negx iz fou lxuelu o ho-hamnx tledk za bgx iyk hocjl iqr ciqomgiat ixgezr. 7. Agxihu qwo su vvoqh qei cervovh wgi iykium royvxiar. Gna ukeur ridrels zepaqduhix zjax fma safx rak xuxgeng mfupa algex sgawqy aji juhtucowk. 4. Kajm buex gimiowm hexqxaalac, teo gfakj eaf dmi yuvb ow qiuhxuwg lepuasf.
Alx vhapi woa yaqa aj. Xou’be kig qij ab ofzkulalqiet ye Mtofr’m nazuct yadkegvovbc neivihok agd isla neah a dcool adahzse iz gof za wedw jadg UTNVaknuep. Ix kpi gabk aroqele vei’qz vadqahou tietotk ih Xvovb’z jiqirl wicwavyabwm yiuvujoq.
Qaa ci rpici! :)
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.