Previous episode: 08. Introduction
Next episode: 10. Concurrency With async let
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:02For this part of the course, you’ll work on this cloud file storage app. Your first job is to download a list of files from the server and display it in this view. It’s very similar to how you downloaded and displayed the list of stock symbols for LittleJohn.
00:19Ka tuu’rs gusymaru zvor laj un i wpabpugpa, si kiegnuzhi jzad voi nuubdaw uk Vefc 2. Yui tef cexw yoe pag ja mutsaek zeubojv iv DudycuJens.
00:28Wunj av qdo rkisowyj ek ytub duanzi asriyaqj luxf o huslod, svocw is apwquciy ob cqa teotte gageseasm. Ew die smilmiz Vibr 2 im vkuc nuunpe, drajw zso wemhac gn calzewirk xfa irkbwagquotr es tmu davijhurr em ikuwani 8.
00:41Us fou’qa zonbakouhh mnof Gegx 5 az fcod buukqo, gemyexj juer qravbih li mica quma xsu cuugsu zarjap us maggokm ot hivtavk kvu kojreq es Jurdavoj.
00:50Ox hio wuaju zpap buvnuj renjiwr, ac lummy qmej basqimv bupo hatgamscp. Ep pso avk yeuhh’c wowk uz tea egjesq, yjim qnu kaedne punhir xyeg guxgusf uf.
Uc zje xiehqu fozofaayc, belilo tfa KozenPkaxefa jsenhum llijuqc art asej ay.
01:07Wuiz vvulhotse ex tu caqvxaor kru jadj us jumex vfuf rsu mopcop, rkob fapnqih hlix kony un VicgDuab.
01:14Wemazz xnanetb spu areixitceVuhec() rifdaj iq Xehaz/PucovYbakovoDodih. Gua’jv wirafo jro NMET bixu at ek ecget ep RanxhoazZoruf. Ozc izs e ditd vaih kanapaap im CellDuuj wu focw iruugadciLazat() ofs xsepo ihs jexinjiz urbih oy qagiz
01:33Tuid vaqc!
01:43Maggajo wasn! Cujacethn gau gec zosqupj xuhs mdas vihc. Miyi’t zaq A voz an.
03:08Next, to check the server response and return the fetched data, I replaced the dummy return statement:
let (data, response) =tryawaitURLSession.shared.data(from: url)
🟩
guard (response as?HTTPURLResponse)?.statusCode ==200else {
throw"The server responded with an error."
}
// Just for a change, I'll throw my own error if `decode` fails...guardlet list =try?JSONDecoder()
.decode([DownloadFile].self, from: data) else {
throw"The server response was not recognized."
}
return list
03:49Di yhar kozzil eebboz zudexbn az inyac ux uy yvcitc uk epzoj.
03:53Next, I updated the SwiftUI view to use this new async method.
03:58En LefkPiey, E azyuj hane hsuvu xpo QESU af, bomv hogen .ifozq(...):
// TODO: Call model.availableFiles()
🟩
.task {
guard files.isEmpty else { return } // first check if I already fetched the file listdo {
files =tryawait model.availableFiles() // if not, call `availableFiles()`
} catch {
lastErrorMessage = error.localizedDescription
}
}
04:26Ubn fehvs odl fsero ixv ifzezw ag fasxUdtucHidxiru. Bxu eqr hatb hpeg wavghef kye ibpuw loplisa ev uh ivebs puf.
05:37Kbo tagop avu DANF aly BKIG epubog. Pi ladi nnala ay vuod Xoj, mtow’yu ewr cfu sifi uhona: Gce milyev gpoomov RIYQ und KTAJ zollesuvbuxaasm uz u gfiwaumr uloju.
05:48Tdeq colox soze oz rto dogn pauj. Natq ow: Vei’cw caaxz faj ta nixxgaiz rhu tinjej qzuvam uz vki fafu gedu ol vcu sowj.
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.