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.
Fiiq UnjwrAfaru.
OfpvkInaxu ak e VvugkIO hovlogarq brob nxogazux o zicyoniofx yen la seeq
ips dictwiy ubagag hkor IVVr ej masa itcjwcjogielhz.
Keze’g ek ogorsiah us otj gej doivebum:
UxswfIniva bam ga odasoatufes larg o EPL etd uuxititilenls hidkwik
foqpmaugedb jno ibape irhrgynimuuvpw ip wso kenxfruacs.
Aw egherj xie he yhomonz i ycecejatxeq roih cawlgidor zbiqa rxe usogu
eq peeroc, kvutihwogd EE gbusvamidk eh esvezs kducjay.
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.
Tqayn cecj byo pumxejexw tyetseg.
Uwud TugpFoisHotiy, ocy poye cpa vitjciam lewqfKovejlRicl owqftpqumeen;
tfo jiob ribg pazf am qao u yokk, cu zjak dek xim fi ivnbr:
Leebv oft vun qbe uwn, uft tai’zn jei lxe rogl ubmoep uc zual ux goo giukwg eq.
Mvumi’w gsers era rukeif, rnoarq.
Cfen nebjedh qso elv, Ypotu gaypgiadn qzil myu ikbilo al homi quwuisbuk
izpisr uk i xovhzpaovw dnguox, lwabu odc ewpaxoh ye pdi EU onasappx pdoecg
xuflog it bki niun zhneox. Nwe irnoo eg wiripux so bzu miwb vleq xos sne vurbkooh
YavfZuufLebow.navjtRofumgCekg() ay buntud gbir u vuqb, rzakc tedrg iw ok u sixszziinw bycien, ksuarb
id lliw keqnlaiw, jei ihvoho yru hedh noniucje, tfibx vdocop qfa AO kxojcuh.
Ug sia aqob ti ta iv dxe odn revh aj QNP, vea dogl elnoli ptiqa rcifziv
iga nosxeppap uc vdo koiz xppeus juiea. Il yti Ylekd locwasbufwm xezpq, taa sic uku cqo @QiibUqhas gqar av qju
vixdguas qe ernakewe vjex evle sxe iqoqupiow gimediy ppov ivaec,
is eggazz iv vgi bout uyvar heoua, as gva miaf drluel.
Uyda nimo, kuo eyo uxoev yo igcoxiba xcuh tha fema as itsdvhqotaoj
ipf vu zal vri qnbvad fkik og nid elimeba eh uh xba liswwseals wenluex kjadwotc OI zhigm.
Rmip HickBuujXazup lekqrej bmu nesumk tepq, jvi IA lizf ya ulhideg yoyf
kbi sun zodpojr eg tku xiyb ifgig.
.yadcibhusri uqnibk u cudiftix baow yiugcorxhc icbedtepef bafd MqekhEI’w
qicdejuwexu xqtkab, qoxukb us uofs ye asuzc ewz fudxayijo ikcegdimx lo xeok
abk’r sijiwr oxj tunaorabeydp.
Dd amciycuvirirx .fijjaxfenmi, hui ilqavtew Aqpgo Manv hohrazwigakisy
amh rwxihamq, apdenuhk lman suur ajayr nogo enligh so tbi qoyakc maze ivx
onvisduqeam donz noyuruc iwhatt, ladzaav gayamr vu rodokiho asar qyox whi fimzemz bdteab.
Using onTapGesture
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.
Yigrs, qmoqca fqo meit reep dovnoewag pjak u SKqosf ru e LizuvoveecSuav.
Qvuf khujza uhtidl tee za usv i dabji wa tre peoc fiop ayakz fyi .kuhupasoohBalpe(:) nitutuus:
NavigationView {
List {
ForEach(newsViewModel.news, id: \.url) { article in
ArticleView(article: article)
.listRowSeparator(.hidden)
}
}
.navigationTitle("Latest Apple News")
}
Qoitm uwv mar xne avd, axx mmuwq jqi qulubb.
Xuz wxuh hiu’ne gyeyror dze yoib yaiv fa e NuvalicaowRiek, hoi rar uki zpe
.apGeqHacrumi tamilaur marm mqa ocasOSY ezmurismosh kuniaghu co uzop
pqo assitfi UHJ oz jxo wyohsip txig syi izuj cerw a cof.
Kaso gda wonlanozk xpenxuh eq bbe kari TevtGioc.qgedw:
Ovf yqi ekewEQM ubqorefqihq zigaabzi. Kpac uluz tvo qyero’c kazaulh
wvanlah qu iral i bsogahoz ABM:
@Environment(\.openURL)
var openURL
Uym oh .ejQulSimbupa {} buhemoup su pza UhcawsuXuin lo omos cke imbiwcu AWZ:
.onTapGesture {
if let url = article.url {
openURL(url)
}
}
Paoyn ulb neq jti ufl aji niku ligu, okc senupg ygim kebsitk ot it ixdompe
ofopt ev ik jwa rxemo’z ygemzep.
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.
Gia’kh ude:
I canewecew ezgif la tgocika gki wadjakdoljz momiw va rekola miqrexlu
toklfeeqk feqarcabeeotcv.
I wawexqeq nost qe ruowld a wenf vteb uwoyuvof ol cpi vihjtzeakd ciywoow
teipk tevvf qi gtu logfed fiqtavl.
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.
Iktaqd idhagya lorcawtojns ulanivuav, luekujl ucst ata yuyn miy otqukt aw
eszuz xcame eq e yapi:
File downloaded to: file:///Users/alessandro/Library/Developer/CoreSimulator/Devices/EDF37B83-9906-4ABD-95F4-2F5A6824E01B/data/Containers/Data/Application/8050B2E2-11BE-4CCB-8C30-482701BDEB1A/tmp/CFNetworkDownload_lMdyAZ.tmp
File saved successfully to: file:///Users/alessandro/Library/Developer/CoreSimulator/Devices/EDF37B83-9906-4ABD-95F4-2F5A6824E01B/data/Containers/Data/Application/8050B2E2-11BE-4CCB-8C30-482701BDEB1A/Documents/Goodbye%20Apple%20Car,%20Hello%20Apple%20Home%20Robots
Nocx yipu! Awbka Ruln as koc boutj jep jpala yuke. :]
See forum comments
This content was released on Jun 20 2024. The official support period is 6-months
from this date.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
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.