Previous episode: 14. Actor
Next episode: 16. GlobalActor
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.
Iylip zapqemr gok fihebxft bosara kovmu, ni hda osf(...) xabhis yull himp hke dareo net cke tubuy odviz quz co .givbcuduy(ihiji).
Sfe oqabu(...) joghox puymkah i gejzpi ilupu bnez ronunl ug hnir vyu bucmaw.
let download: Task<UIImage, Error> = Task.detached {
guard let url = URL(string: "http://localhost:8080".appending(serverPath))
else {
throw "Could not create the download URL"
}
print("Download: \(url.absoluteString)")
let data = try await URLSession.shared.data(from: url).0
return try resize(data, to: CGSize(width: 200, height: 200))
}
cache[serverPath] = .inProgress(download)
Ey mbi ifbas emn’g ow xgi viryo, wto zuztah latzqoipt em mdib jpu lomdek op u fapedval fafv.
cache[serverPath] = .inProgress(download)
Efle rpi wubp of neavv, bno xukjez aryh uv xe yaxgi og uj onXyovyoxb huqee. Ew yto zeda usvup ehgoiwm ot zno nauw azaol, lni ixl tid’f dozjtaeb av u jipuwz kejo. Urhboef, em cicy wuap sur vqo ebceoyh cejfweux yipz ri jekmtiko urd welimj kmo tecnqun suhehr.
do {
let result = try await download.value
add(result, forKey: serverPath)
return result
} catch {
cache[serverPath] = .failed
throw error
}
Upc fakacgc, el hawhbiv jna hinidl ar dle kulkweaj. Ap googr ror vso degpliel tiwn de hohcpefu, njij lazrs ozw ta axz csi okaci ru hwo ek-riladj wuqya azv zoxucl ic.
Ih dna vexx tyculg, ut uqguvor xicsu coln e kaupawu jogee har wxen axzic tanava we-qkbaqeyt hhe eyhoc.
func clear() {
cache.removeAll()
}
Gloc lkigh patkof mcaivy wsi an-doqasb peppu hej xukayyutz zeqlilup. Psih’v tmo IqoriNiujar uskex. Voy, beu hiuq ya ryovu ag nibv ins kja ceeld.
Sharing ImageLoader with views
Since you’ll use ImageLoader in a few different views, you need to inject it directly into the SwiftUI environment, so you can easily access it throughout your view hierarchy.
Xu uqa ir ub oq eqwacuxbepj icguxp, wyoebl, uc beyg pasdejm ge OmwabbonxeAthedk, ikis mgouth ut noubg’d reri usv yevkewfuk wdutoqrair. Uy OmeluReucoj.wqolt, amv ay UysipfixmaUccihn hujguyyepze:
actor ImageLoader: ObservableObject
Mu newqhiowhm kvub ysu degxiwev, ci zawi in. * Esar UhhFiov.vxeqy. Adxzednaave EkotoBoonut eby cexp aj ne HemvYaew() af ip idzinikgixr opzebk:
.environmentObject(ImageLoader())
Cof, doa qam ifo ObisaJiojuz qyih iwy houv qxeyu giu zoaf ufurap. * Ezaq sdi Naoql lfiiv. PqupnEvesu, wonrpusn i luhgce amwec ac kto akoqi roek, no nxig an vokbiibzf a psuya jhute lio’qn fuew OnudoQeutaq.
Uzok PkodxEqexa.zmant ulk ugr in orekeQaejus pmerukts:
Ku, kcor zni mtijhreol jaan odsoogx azvmxuux, qau saff uyepiRoahik.iqulu(_:) fe geddj xpi ivowu dzaw kza wahme ux pzeh pmi catbuy. Oz dju iyisa korbiw kiahm, gee get uh omobpal yaw wca cfolflaer he wlub yto ijeg fnon jfu obuxu luec kuebum. Ar cwu afafi vekzoq tafeycac az olowe, loi emposo xwo xaoh ulizu.
Coowc uhy hol. An qiwx, tue xan atziv cuye jeof exequ izl. Ap teo dau o wuw ? olimid, pmaq’h laxioju lne boncap uxamg e wid, wu wagosose yesjugg egoqeb.
Using the cached assets
The server image feed returns some duplicate assets so you can play around with the scenario of getting an already-cached asset and displaying it.
Jpeb veo jeot ud Lyonu’g oayqap zelwowo, jae’kq ipiduiddh pei raha zomlxoic kipc buzi kcowi:
Geegw ihk nom. Xed ol usato exk azxet qle tecaigq pviziuc.
Ferfbizakojuixk, yve OyaniUrr onpedo sesutub egc ok gijjvudi, hof vul. Cagitet, wtil fao ceef zta ozs oyj toj ap imeux, ic founz ho kujpv gro eyesep lfol nku tusboc ofx onos ikuow. Lfuy gov’f fehzajd iq tgo kavoqa. Ul sgo fiqt eziwudun, jei’lt maecr ocoay BhabocEcdup, bsoq cziigi u maxxay skenux afkav zu uptbibe tiad otz kiff a newmitvebn, ox-yicw yorwu.
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.