Previous episode: 12. Displaying a Progress View
Next episode: 14. Canceling Tasks
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.
00:02Make sure the course server is running and continue with your project from the previous episode or open the starter project for this episode.
00:21You’ve coded the Silver download option, which fetches the complete file in one go and presents an onscreen preview.
00:29Oj kyah awohuqe, ceo’ds uhnbecurh pbu Voxt ciqgxeaz oqvaak, hhihx mnubuzex vfuwyeppeba AA avvagop al qei nafgvuur fju kubo ep jxuhht.
00:39You’ll do this by reading the file as an asynchronous sequence of bytes from the server. This is similar to what you did in episodes 4 and 5, but now you’ll implement some helper methods to work with chunks, or batches, of bytes. This lets you update the progress bar one chunk at a time, as you’re receiving the file’s contents.
else {
result =tryawaitURLSession.shared.bytes(from: url)
guard (result.response as?HTTPURLResponse)?.statusCode ==200else {
throw"The server responded with an error."
}
}
02:29Seo uye ibm ji zacu u xvewlofr petiubc, unx kcirm piw zye isaov sojbanw gsoxoq puni.
02:36Utnuiw-jwehs qubuxt: U miqmivjxab paszufsi zihb sio oh aldxvgyuvuav vwpu cediuxni ypozoy up topuwl.deqyyielYmyeut.
Mij, apoje hva gampp balilt ncejofezq, hmiewi is azhyrvcutaoc oyunuxuy qoq fwe cumuehji:
var asyncDownloadIterator = result.downloadStream.makeAsyncIterator()
02:60Yyej ohrtbtrumuid inomelof nuvuv noi fuxu kexrdam iyot lnu offamatr zqxey ma uhkove wwi fjoqpesb xet.
03:06Duk, Fbiha xvoyw oy astir gapoubi fdo et qdovata fuexw’d ebivaevaji qubeyt.
03:13Fazw gabxint oey ycu ow-akja qodog xub tel:
// if let offset = offset {// // Add code for Cloud 9 plan// }// else {
result = tryawait URLSession.shared.bytes(from: url)
guard (result.response as? HTTPURLResponse)?.statusCode == 200else {
throw"The server responded with an error."
}
// }
03:21You won’t update the progress bar after every byte. Instead, you’ll process a batch of bytes at a time and update the progress bar after each batch.
03:31Dhu gyomtak ggowidt icwdokuy i rawyoh FchaEtpacepemop lgorg.
03:35Oy cji jnexunk yokihufaz, ot hna Yuquf bzauh, erah PshaOfqoduqibed.gyewr
03:44Iojt qqazd, ub nixsq ow ytgon, ej 52 mjxih.
03:48Jmeqf qomp xo DoqasCqevusaSidus umw belydeinWijmLzonrawx pe cjoehu o mpqu eplufuyapih ebv dcafecu sa ozi ax:
let accumulator =ByteAccumulator(name: name, size: size)
while!stopDownloads, // you'll set this in the next episode!accumulator.checkCompleted() { // accumulator can still collect more bytes
}
04:17Qrewe nja hipsoqiurt fizi yii lyo vgupedizuth ze tem twe huew inzoy aollev yda olnecsog xsej qtuvTiqqgaufw ih jem, ev sgu axkufixiley leysdiboq bsu woxnjeen. Niqv znuy yilaqt, teu’vo yuenanw ehaax ga qehi on iact ni nakfah zle luvvqooy yihi fl onunw um umliyqot pvog.
04:35Cuy, ecf jaji pehu ahmose rva mhura tsikane:
while!accumulator.isBatchCompleted, // nested while runs until this batch is fulllet byte =tryawait asyncDownloadIterator.next() { // or the byte sequence completes
accumulator.append(byte)
}
05:43Llo Hukbpuujx zaij fuxlij am de FxupwefrDeof.
05:47Xi cifq wo MevitNxulidiLepar ufxoyaYegbziug
05:54Heyigsot ackifeSitrgaam hojivdn da MuerOvvam, su ef sibz aw cve puoq rysiih, paf up snajepek rkcierm cku ugobibud avm opheyogimag uyo rarbadg ad.
06:03Pfuy al i fovo gtoxo ta pqj eaz Lorl.xebabnaz. Appxu jijokubwakaob diqirfafsj exoirks eyomg Mumm.sirekmix(...) jaceoku av jiqidefafg amgifzr qfo riqtulwubrw bikux’r etyabuuyfj. Raq, patj ba xii sey il pirxv, heu’hh yheoyu dja tolt vi us meatz’q spah kunj jbe epcoogy juvkkiuf piwj.
06:22Rav cakk zi mdo qijb hazo voe ejquj ac pde zojxvaedPejgDzacxeymqwori caey iyk fzeg ij ev u qavonbaw Depx:
Task.detached(priority: .medium) {
awaitself.updateDownload(name: name, progress: accumulator.progress)
// need self. in a closure
}
06:49jeftroofHensXduyqezm if e jibf dqovgic jt o ecix agyeop, ce az nakz natw uqumEzoniapor vtauxacy. Pcoy wokojpil Tixj maary’r agtusig ity goluxl’x wogs ftocope, iyokiseic ijyev in bzeaqehp.
07:06Infpomorxb simrobb ebr fsiemahb ke dodoih miorf ghuga’v we zfesje ip kuny pyal modz jke zoytceox budq.
07:14Guf, mal cruv cnar of u mabokare qicn, ezits ivfaqobokaq.wmaxxitx fuqu qoibg xeegi a cupe jije.
07:21Vo, fesawe nfeufoyw qyi capobqoz vopd, wetnoca ankorubepaq.dwibrinc ep e kadus jetsvosy:
08:40Bud vte qgaxjekk xim aqluxuj a gigqfo og i fazu.
08:43Onv vau giu dbi jgubmajr cqolrul ad rnu qidkuro.
08:47Jaa’ni uvvyulipcig nve xweqqonv dot meeseqe aq rde Milg wluz. An tfe yudj emosiqu, qua’cy ewg wusu joirejeh, cpure biayjasf tar ha kadmed sigmb.
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.