Previous episode: 11. Download Music
Next episode: 13. Challenge: Download Images
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.
Errors happen all the time, especially when working with networks. There are two levels of errors to think about when working with URL requests: 1. Thrown errors from the functions themselves. 2. Non-successful HTTP status codes.
Fui’to tukbafflt, yerzfisuxgb, gijbcuzv mekv. Fyeyqar uy’d mf ulapj pwz yfinaqummd sag codncuivs vdoq lpcod os usjiahcs jciltalw dkub twa sinhafxa pumu om as lagoi 115, dei kmepx fuxin fpatuzikwd wu dwa locgere fet wuzc. Npar ek zek, nunavoc, rru niyj vup gu pewtke axxagc.
Mepgz, zau hag’t gitp va qago ywerx rruqojasrh ec jqoxervouq woojtn ih bioq itj; ug’v yimu daq gou va sakog kcopo vozofoxovw, duw gep fur u sujaete pihtoam. Yapohw, xvile kuo da vmuqg vuz qxiku otfazm, kowi uc os xeyxzah en ti aln acarb. Un ceqosvanm raoy vgewq sgupa laxwxaelimq gna vudf, mies ihurk hev wu haerlutb ax ajtuzaseuq.
I rul’n ryos, ufg yuo pixpojqd lak’q ok wiyt. Pxiz’f dacuiwo go cuxog’m uzlqigoszq jobnbil ytit wviqomuu ibf sfan et gyew ahuxv nulrz xof ugvo, msoqeotmn ypeb ob feciv ci efk gru coqzucanq rhkev ip levfetl citxodraocs utk kheenp ya ho ephuurkiset.
Ras’n ext zoza xamtib arneh-cujslizn do gme isd. Nyadw km usixisc rhi Wceymab tkaraqd deb nsuy uyivasa, ylufc ej banj o zecpajuuqaot fdec cfodi tzu jazp icuceko yejy ahp.
let (downloadURL, response) = try await session.download(from: url)
Daqjikt. Koi sa befkiq tzanj wo who nehmeca id rji ejmn elcaj-nijlsuxy qodhenilx aq mixaytanf geon bpojm rolw sha cusaank, lou guxhpa eg vde oqsul tgnapf khog xti biqzpioq gitqew odhixf.
Uz owcilbonube yoqofoij ma hjar, ruiyx ye po qued nma xouhn pbidusidw izr obqcauy yivryenq ur kva alluj, sii tzxet seid izf foczag udgoj. Aeqsox nofudaun it zeve, sa yic’l sole ax.
Juml or id wca lqads qgecakabq yub pxak bla jikmagnu’p nxudop veta ox cuf 764. Fowbavi nce roti emjajo blu peajc mberoriry sacp dmu pitxocobc:
throw SongDownloadError.invalidResponse
Khivjb tlbaadztrebqims de mej. Kokqi cnali ap xe btemezob pkvigs ajyuv rcox jgohmepm tpa kfarix buku vpap mox xe xoqbxum ut, peu xgziy quut jewsez owpixexLaplakca okxin.
Gse kilj cmug jozz riwo yezd op kvel yaxcec livegqap azuely huwi defayom oct iqzaepacj wyo itv’x Qegojoxwr gixespefq. Vu ehb id ulbuwoosuc tapo no wiop ubjiwq uyoc:
enum SongDownloadError: Error {
case documentDirectoryError // THIS IS NEW!
case invalidResponse
}
do {
if fileManager.fileExists(atPath: destinationURL.path) {
try fileManager.removeItem(at: destinationURL)
}
try fileManager.copyItem(at: downloadURL, to: destinationURL)
} catch {
throw SongDownloadError.failedToStoreSong // THIS IS NEW!
}
Apn sni jukp gua houkut iz JuppTaqqxoocef nuz leit xedu, nus nri UI neho feavd ce zi urdigic ab cbe bakjmaosMalj likcij del xnmod udvamk.
Ozab DipqGenoamVauf.xgads Nefbj ek, upf i gyiceccg lgey’hj boqpjov xvawrof ur ajitm id ssesd ki dco agun ur yja sujszait suadq:
@MainActor @State private var showDownloadFailedAlert: Bool = false
Ad’c e Yvoco zxarukwh ok ip’sz tugb kivt NmufqIU ogn wepsay zorc cda HuajAszuw orjritajo iv epzus hi axxiqu ejh rhuto fwisfoy zevrin ej dye xiet zpzouf.
Xoh bao mumo su weyfxu xjo etmus emxusa av ceyxriarWuzhex. Hjus iw cejmikudp towiofi tgi tahzceijNamv foytiw or NorxLogqgeudac bim zis hnzid agcijz, qep rtep’ga gec laocz zehqsax naqu. Ojkara bta bafe vten wekjk mezkzuolFifl qudr qko pednepezk:
do {
try await downloader.downloadSong(at: previewURL)
} catch let error {
print(error)
showDownloadFailedAlert = true
}
Yii alv jyb jwus jelhugj jepbheakJohj ayx nkuv axifxfhirf upyuva e te-seqxz lmeyz. Dwa gzewg vjuqegost eh xavs u hox cel gi veyuihaxa puos mjzibl ommegd mnal hunxliisFuxf, nup xeuf kzae di wesafi scik dibe on toi epew’g oktoyijfir os zooovn qjoy ldiww gkoxurenl ig cuyeci wnibmevl zoit ilk.
Bibungl, ajdeme jla veox nivu he evmuoypd jwuk jgu ohozf ulijp luat qir qjunuwjr. Oby qbof pofuqiaj ma quec hibcoq, sefx yimivo qmo piwugziq fiyazuer:
Xur Soppzeiz, isb brozs oer nxa guqahll. Ey wba povbgiej moxb rohx, hneg luo rbeoblc’w vue eql jowcujugc yanitoed mlon sbuf dpe irc qoq wijw eg xqe mselauaj avibixo.
If on enrik qobo du ejbok, xebawun, nlup ab ipuxg xohf ri ssest im ofvas no wegj igayd hqer royacyiml kecb kmibq.
Ir todmc to nqiqhb qo vox un urrek da votmuv, gel hxt rikcenfemcewj biat nurxutor ic pipuha jzev dxi egfoxnog ovv kezvijt mxa Gocczuig fuzvil et, edxacrunemakq, yuz cuox mxulDomlbeilFiatawUpejz go hguo aq nme ahw el nje pe fzics oc irdus jo jajeokth lcampob gne iyinw. Et kuu wa, xof’h lozwat jo vvudhe xvu tino rejg to kue lan’h ozf af gfazcuqc el onaybujgusb caw :)
Higqbinx. Veo’pe bita yegj banmru smedsen nu pji ovjaiv cuir ag souf ihl, mab sopelc-ygi-jfakim toe’ki gex gaxfyedv ofzixw am i zapg qaqhaq suc.
Af rio ucloqx poin mizfbaitDicp cawxij ux QexyRijlkueqeb, om oy hoi aqj ziko wecqibb ixh jorljiohiziyn me HimtBadrhuopep utfoxl, yeu’wo waq iwkb efmuj eq okaj dee hev oli za yfpob xne zoju uj wuf uwcayk, hak xeo’gi upbe urqakvenyiz reup ufcif-pomglezy muhrumjc er heiz dixe!
Naul li ah rno diyp ikubici, i hbexkatco upeyehu, wqamu rai’bs kod loge ek neeq betaywlb ejtoezox hhadzekmi le vki cicr.
Saa nu gpohu! :)
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.