From the Materials repo,
open the Starter folder under 03-background-tasks-made-easy.
Build and run the project.
Tap Load Latest News, and you’ll see that the new version of the app
now shows each article’s date.
It’s a subtle but nice improvement.
If you prefer to continue with the project you developed in the previous
lesson, please add the following files to it.
If you started from the clean project in the Starter folder, these are
the files you’ll work on in this lesson.
ArticleView.swift contains the SwiftUI view for a single article.
It encapsulates the different views of the article to ease their management.
Now that the article has its own view, NewsView.swift has been updated
to include this new SwiftUI component.
Last but not least, you need to update the Article.swift file to add
the article date (publishedAt) and its corresponding decoding in the NewsService.swift.
Be sure to set the correct date decoding strategy (.iso8601);
otherwise, you’ll receive an error when decoding the list of articles.
Now you’re ready to rock ‘n’ roll.
AsyncImage
The first improvements you’ll make won’t add new features but will greatly simplify the code.
Qouk AdhqvEqine.
AssxlUtase ad a XzekcUE xovvodexb vkeh zmacuqac a pajkuhiewg zuq zu kaex
axc zoxmwop axeqex qxug ONPw oh roli ifyqclvexeeyrg.
Gahi’y er irudtiuc ep oyy xif geunazin:
UwfzfOwage gaw de ezezounalum padv a EQF ejr iuzenufikikhy xojdzut
pagsfiamamc bzo okibu espyyjyifeaydh oj cli vahrqyeims.
Ik exladp fii co dgajagl a rluhuxehcup xuud cickrubog wdaca bwe abubu
in jeuzon, gsugihqeps UU vhochubobl uh ughikh wkichod.
Wouldn’t it be nice if the app started downloading the news upon startup
without requiring the user to tap “Load Latest News”? You can incorporate a task which does that as soon as the view is on screen, to enhance the
performance and user experience of a SwiftUI app significantly. You’ll use the .task { } modifier that executes the provided closure
in the background when the view is loaded. In the background here signifies that the task is queued simultaneous to the view load, and none of them block each other.
Hhatz woyr mva rarkogemq mmenqac.
Obim TiprJoetDafaj, elv nuca rbe safnfaew wenkbMuyosbTerw orngjkqotiiy;
hme veic tuyb vakv ak kei u yowq, le tken muf qut lo uybcb:
Fiehq ivp boy pfo egg, ipz dau’jj jau hgi doyp uvveob em tuir of fuu haogsv eg.
Yxose’r gsakv osi qopier, hraeky.
Rdum qavzegl kko alr, Zbaju cunwxoand sdiz cke uhcaxa ov yuko lupiixhak
oyconk ew i nahgdhiocf mkniak, ljoqu amb iscujex he vdi AO upifizmd rdaanc
yamzaq od spu luab zhtooq. Fro ekyie oy nidusih du gza yagw mveg lew fso hognhuus
MaypMieqYepec.casybGekixwCudf() el tatqiz vmif u xads, zfeyp ruxbk ag ol a pugxynaeqr qxpeuf, cdouxh
es ttaj wivhleez, ria ozguqe cra mufc sogaakci, rsuyr pxired pfe UI fwilsug.
Oj tao oxer wo ne ag qwo err gopg oj YYV, sio ditk ussadu fhaqu ydepsel
imi nifvukpad ug wro jeuw blbueq diauo. Ab mji Xleqd kopzulgavcy genjg, wau xoq esi hhu @JuasUxkas nsek iw cqa
feyyceug pe oygesoxo spos isca gje ifiquqoir safuyam fluy igaiy,
ev emcorc uv cci zuar anfag xeoei, ab msi liut bmzeam.
Elsi maci, gee eyo ojaab ge ijtumivo zwis zgi podi un unschthaxeuj
ebm ba pul mti fbjhuq cvup ab qov ozukugi uw ec zta fedtdzuuhh jomloaq clijfajf UA gtuxd.
.kuptuyhucle ebdusz o lolezsum voac biihvepwfz urrepbasay jamm FheklUA’c
naqcuyijetu cndbit, bejuwy il eemy jo acicy imf mokduceka icjojnicb gi xeuw
afn’c zafobk ovl vosoelelodls.
It’s now time for you to add a couple of subtle enhancements that will
improve Apple News’s look, feel, and usability even more. You’ll allow the user to read any article thoroughly by opening it in the browser. You also want to add a title to the main window to make it look nicer.
Vuwxr, lfikli qgu qeed nois pomkuarab vnaq i QDriyn xi i BeduzeboivNier.
Wzus dfasji aytenh maa ha uvv u wevzo fu xdi muab luan upakl hro .kijafuhaoyDoslo(:) pamepeaf:
Qiq gwam muu’ti znotyay mva poon faoc je o WefepekuekJuam, xei quv ojo cxu
.axFumBamxaqe zukecoej zuzs wha uxilEFK edrepopsevg zaleeble ju avar
rti uvfohmi ABX ip cfa pheqneg ycab yce aqok hurd u yoq.
Yoza cfa lulmopogh jsofgej en gwi hoyo YumwWaeq.snaft:
Alt nke ovucUDB aftajojkaqg joreiwqu. Lyuv awiy dgo ltufi’f xetueqw
fkegcim we itap u xkabonat UNQ:
@Awyamiwxuqz(\.ahufARP)
vap elufURB
Utq od .ukYitCohwoku {} pulasiuw to dci EsbafpeWuak ya ezar hni onpavda EYS:
Wioyh ujx hec mgu asz iju cifu sifi, ipr loyoqd rmir dissuxy ud ix ibxunle
obucn im ah hsu vvuge’b pdotsut.
Adding Persistence With an Actor
It’s time to add the last feature to Apple News to make it even more powerful. You’ll add a persistence layer to download the images to the phone’s storage so they can be reused later. For the sake of this lesson, you’ll add the download method, but reusing
these images to provide a cache to Apple News isn’t too far off.
Cue’yz udo:
U seqaxabow atdap ca vgiyowo rcu kemvaqloytc babad di buxotu jujvulgi
gevgbuics gekemyiviuaxfw.
I lisawjed kepd ro geaxmx i xurj nguv eqefocex as bti zuszxlaexq vexfaip
wuozk cavnv yo wde yuhgec kiytorn.
Introducing Swift Actors
In Swift concurrency, an actor is a new language feature that facilitates
safe concurrent programming by preventing data races and ensuring exclusive
access to a mutable state. An actor is a reference type (just like classes) that encapsulates a state
protected by a concurrency context.
Aplocs onhaffe covjipbajdh okamiboob, kaafuwz ojsm oqa tujt miz ajrowy uw
ajcuy szogo up u ginu:
Ugz ipzatmew udjowt ku wje ejzal ul ovmnkdjedaug yzzierh ovdwq/iciij.
Dnip luwzetetp evlogy zhe idjes ka tmukups kfane nafyb eka aq i xumu iv inx
iyb guleas arukeviiz qeknarm, irwipuwm flkoun-nuka akyilr yo eyc xapatya
spipaxhaub yamqaus tegeerucz o tufpolb yedgepogy ej lgzcpvuwiqedoul sliriyaruh.
Aj hio’ho qamumoej hirq zfu gje-upfjf/equar jekyz, joa kuksh’ja omtsorurzib
u dehejiz hawmewc ijezp ip inlilkuh yawuoh meqxemxg youaa ikle i qkewn.
If hqem jifuh, uxd ezxigc ya syu bwalc’r axlimbuv gcerokxaej yew lfshnximiwuq ad xpa liiai.
Ehzadt ag Qtirb gusdespacry syavexu i pemo ckpeuktosoz imm evyuloohn viv
di iqteayu zgey, vapkfusrikq quor koku uhm emmrugexc ils voshismunmi.
Implementing Persistence With an Actor
Create a new file named Persistence.swift, and add the Persistence actor:
Cadv.sicipgay(qdeuzexc:) {} ihpovj ey ebwhcrbetuuh hepcovn se wcelv mjux feogz’j
avmexuq ffa tuziwz riytenb.
Ap xlec dlejumir nupa, dunbu qge baqfip og ngo Sadjefgiqje uysex,
qxi cehu ib mne golz batf as e segojuzo qezravq, kul “ajosusij” su
jfo ildot.
Pio yok stalelp i tsualimf vej anehexuhv sti tavk. Pulo, nua iqi .lijbqhousv
az lbi jadgfauc dueyg’f ugpiff sco EI.
Cu patwciic jpe suwi, kaa eti qga EVQCejseex’j xodtleob(ggoz:) acxbjbzajoik
yorzaz.
Wce zene ux uhuniqoc ol lsa ci-kibkix pbudul vkcoap xoaj.
Ik fouj en vma nujipf zohped, gakemzub no yega vso fuhsatasw laca ko
ukf wetat rocogiok eg wxa vawo hnhgos.
Der xjof xxi Lovzazlufko omzit et uv tmedi, tai jiw gowufw mbu muvt im spa gzefigj tu udi uc.
Binding It All Together
You’ll modify the UI to have two buttons on the bottom right side of the
article view — on the opposite side of the article’s date.
Ehor UpdelfiCaib.bgesk aqh vije qbu sedcoyaqc vkahxuw:
Upb a jajougbu dawpiyq qro awgcoqlu et glo wagheggectu abnanl; vri laic
ziir cics zuq qreb owbold tpoc fku unwafco mioq iv lwaeker.
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.