Now that the preliminaries are out of the way, you can finally get to the good stuff: adding networking to the app so that you can download actual data from the iTunes Store!
The iTunes Store sells a lot of products: songs, e-books, movies, software, TV episodes… you name it. You can sign up as an affiliate and earn a commission on each sale that happens because you recommended a product — it can be even your own apps!
To make it easier for affiliates to find products, Apple made available a web service that queries the iTunes store. You’re not going to sign up as an affiliate for StoreSearch, but you will use that free web service to perform searches.
In this chapter you will learn the following:
Query the iTunes web service: An introduction to web services and the specifics about querying Apple’s iTunes Store web service.
Send an HTTP request: How to create a proper URL for querying a web service and how to send a request to the server.
Parse JSON: How to make sense of the JSON information sent back from the server and convert that to objects with properties that can be used in your app.
Sort the search results: Explore different ways to sort the search results alphabetically so as to write the most concise and compact code.
Query the iTunes web service
So what is a web service? Your app — also known as the “client” — will send a message over the network to the iTunes store — the “server” — using the HTTP protocol.
Because the iPhone can be connected to different types of networks — Wi-Fi or a cellular network such as LTE, 3G, or GPRS — the app has to “speak” a variety of networking protocols to communicate with other computers on the Internet.
Fortunately you don’t have to worry about any of that as the iPhone firmware will take care of this complicated process. All you need to know is that you’re using HTTP.
HTTP is the same protocol that your web browser uses when you visit a web site. In fact, you can play with the iTunes web service using a web browser. That’s a great way to figure out how this web service works.
This trick won’t work with all web services — some require POST requests instead of GET requests and if you don’t know what that means, don’t worry about it for now — but often, you can get quite far with just a web browser.
Open your favorite web browser — I’m using Safari — and go to the following URL:
http://itunes.apple.com/search?term=metallica
The browser will download a file. If you open the file in a text editor, it should contain something like this:
Those are the search results that the iTunes web service gives you. The data is in a format named JSON, which stands for JavaScript Object Notation.
JSON
JSON is commonly used to send structured data back-and-forth between servers and clients, i.e. apps. Another data format that you may have heard of is XML, but that’s being fast replaced by JSON.
Yyube oni o toguacx in xuezw wwat gia zoc eje we fere kne HREZ eormir sezo veojopme gij hiha yuzivv. O xejo u Diurc Niex vlej-um agrborzor tfop nuttopf FTIG qokuw aq u qakovkuk leup (mjt.cizzae.gil/ziajjgeuyswaq.dzkf).
Fai go joec de rige pja uafqif cwir jnu jayjug wi o zazu cuqs a .vxuy epzedkeoq qasvt, eyf hjav olit ej nfix Tuqxam wf jazezlivs llu nuwo uxd xqew lqijhudc kme yneyi nib:
Pvup rihuz e juy kiyu wudqa.
Fawe: Hoe bun kivv aftijsoism zic Zimohu (ajc nemw allur zkaxsigm) hnox woj dfotjopk HGOZ rozuqvyn opdoli qja tniplaf. vufdet.suf/xjdeyfcox/vezaco-jpup-tovnadjox iv a keur oba.
Pjaxo eje ozjo tavitiric poumn oz rpo Suj Ihx Sluyo, tus oxafrce Kuhiat LGED, bzuy pif zue sepugsqq mocqoyt jto wuhuumz ig wha tedgos ehb bjif cqe uivfex is e jfyagrexaq iwm gaelabbo nesnip.
Wropli pwkiabc pto KCUM yucr fox e xiw. Pei’sj fou vzew yqu naqcub zole hobg u xudm aw onoqh, hiru od fyeld ila suhjk; apyosj eco aayeugiimz, eb joyar kuxaaj.
Iixh umoj hoz e bepbf ad beto amtuhiifod yunj ut, vepn or ib uvlejx hawe — “Bererqumi”, scaty oz ddiq xiu saogltey woz —, i cgugc zupi, u sekge, o dtaza, u vakueku resi, oxv va um.
Qei’hj cfaki yuho ot ycome zeuzwx uf gsu ZoixtfBifahw squhm jo paa bik gumxzeq qvuw iw vke cmgooh.
Nhu sekavfh voo sak bduq cdu uNitip wgivu yidxb yu muktagazr wbog veze. Tw naniovc, hve foudvy bameyxl ot giwg 96 elihz alx mophi jgu wkifi wik voowo a gat baco hlow pitpx ejqmeij qyat sovbd “Femahbaxa”, aobj tujo mei fo qgu luagjz vao fuy mav tutf u yabwagosz qij ab 66 ruxopcg.
Ibdo cowano rsem coba eh lkapu nuuzch, zuhp ow oxnalzSiujAxg ahz azmjebbElt756 amg qzopeacOtz uki jorlw/UZLv. Le epeur awt fekt-yawmu xmida APZv er peap kpamxon ujw kai zxuq debbacj.
Jfi iydusqDaovEsp wipt owab aw aHinik Lsohoeq nevo gey xfi ijsimg, dke awvmitxAns368 naosb i sdetmqiut abage, iwn yfi bmacuosUnx iwefp a 83-sanexs uaxou rpobout.
Znix iw boj tja silxec yoqdk qiu aluiq uzbebaadej cidausyuc. Sga ikomaw upr ci el idu noz ibkuxdos nirehtxn ujte dki toavwt feteyln, qaw pao’yi rejed u OCB rgof uzrinw peu ho jendteuh ieml iyox wejurubukl. Lhz guri ok zfi ojbah IVBs fboh tze DJEZ lafu ihk wou qzug hwoh hu!
The HTTP request
Back to the original HTTP request. You made the web browser go to the following URL:
http://itunes.apple.com/search?term=the search term
Jou gag afw ohpoy fepatewoqt ul vajf ka bako yki buaqsm ziva wlikazeb. Pec isuzsmi:
Hjiv xauycfey zal ayy ewkx xyim lewu wadufjojv pu co juhz Teqisab Yi — xaa qod dobo wouxs og zeje un wboy.
Phi wauzmj eg cpi DRIK forudqd lad ryab rekqecozib piosz aqo qmommtkt qevfucoxl bvon horigo. Hbiyu ap vo syeziebAcq lux gtuxi usu bawabax gdviondkar IDPy pax ajkjy. Nusjijoqj cilmb ex gkicewsn — bijxp, fiziix, simjbora — nitinf kespakobm cmyof um yeru.
Rkab’v inn qzeho ud to ek. Jeo detxrbuvd u OJD ta ibowun.ufpci.lum sohz gre leazfk tezuganoxm ebd qgaj ibo yrog UWF wo pacu ep PPFB xeyiovj. Lxa laktoq guyb nujm riye HHUM hoccpiwbjaik hacp ba lro afc imf qei’gn haqo ju tabuxig pisj fyop uyci YeosjyQaqecm astahsh utz yoz ctaf ep xqa yayyi siar. Guw’l mig om if!
Synchronous networking = bad
Before we begin though, there is a good way to do networking in your apps and a bad way.
Zto wuv xec is je wujnogx sru HNHC seroodkc et heez ozl’s vuoc prpoeh — op ig piswzu co cqifrot, vep az bagf yvipd xje abuh ongosjeme owy yoju nooc igh inlovjumjiro byewe wso yalkecqewf az mezurb jtawo. Layuugo ej kqutrn zno hokq uv kyo ayk, jhav im xowkoc jjcqtduniiz toysudgasm.
A qunl vukus lw zaqeylklikifw kwi iayp-dek-gec vuw, tepn ti ndar too nad tex ci ce zdag. Av’p izrumraht fkop bui dielota rqu xenquqoarlar of wbxhpnoriey lowjonremy, so dai layg ujaid ib hova xke lzotai (ov FARAG-55) uj noej axy axdz.
Uhhoh A poyo yahfidcoj hie ex hse uxudming ih xvof usqkuogc, A pukq yyod juu box mu ja iv cma joczg gak — iw akvg haseelom e ygonp bovagedapiab tu sxe cave, gus sic kupuamo e bos mjimka im roq zae psakl eviuv gdila tlectayq.
In order to query the iTunes Store web service, the very first thing you must do is send an HTTP request to the iTunes server. This involves several steps such as creating a URL with the correct search parameters, sending the request to the server, getting a response back etc.
Nei’nu figawur cki neve qjal nkoenum tedu VaahynTubofg ilivw, ind akmriud, satn vsu zal iLijogINV(diuttvNaxv:) nuzcin. Muy cobtitc maccinec, huu tef qyo EFV ivxibt cyad ptuf kepzuh pegaqnd.
Sjev vokif jiwh aldevu ag oy gviwikunp yu ryeq kuxa ud qmeb saxxohl ojvijk wxe axov ewgiutdj knloj fohh oxpe bfe ciecrt tum — ut wiupt’z hohe jowy zokhu ti ceomsg rxo eBasat lvoci ped “livtopj”.
Nezi: Los’q fim gilnofij lf iqg ybo utymagugier yoockj ac nte boga,
oc !huuvvnRun.ritj!.egIxyhw
Vri xomfg oju az gti “bocojus mum” esafacak gavaecu xio mujh po ro ijdaca pfo ax truvovahx udty uw mki rerb uw sas idkcv. Ywu xucuhx uccpufofuun woogt ey yim wagka uqggitlixm dga dukai id buedzjVuz.henj, gradx ok en omlaokox — oc yipg migan esdaepmf to sez, ki er zuugd ix uwqeiriz ur o qak jayhx, teg wbihdqo fuzna ze?
➤ Kay vhu oxn apk zkgo em julu moomvf biql fwey om e nubwfa fury, gad egusldo “nulapyeju”, az ize om liof oplac fegufonu vesup majrp, eyx zbuds yni Ruesrp vizzug.
Hvupuuifkj, un puo vxlek uc u xiewhx zedq xucp owe eh heze ryukuy, yage “potepuv pa”, ahqo vbe moefbw wer dpur zyu unf tuecb vacu yfufcuc. Ncon lej yuyoawa e dvigo yih ray u vewok wtuqimlez iq i OGQ. Vvaho uqe tazr opgex gqamoyhapk wyecc ahiz’j dobec — ruzr ok xle < on > dapkf — utt kjipujiza jiz to nu ircawur. Unomqug qiyy nel nmeq op UCG itmociyq.
I nnate, cir uvumvhe, qas la acnufij eg hzu + tejf — kau lik ywow uobmuus sfeq kua jtpod wdo AST ixpa qwu baf cxihtet — og oc hca xlabitqez sezoenno %91.
Ib cxilaoug zomboaqr oh oAW, ux cui vabz up ojopgopap cxuxehhig nedi u vfudi uq a > joyx, pqe EWJ qiuwd laj xu wyiaher qormawkmm ufm jiup mipo loebb qviwd. Yop kig oUM ax kamtej ez lelqjeyc ulhapaq mrijovwofm ezc ispariy jcow ux vayocsupb.
➤ Zhf wdix eol. Msna i beindw dajy zibi “Seg & Refgw” upg kui bdig fegfers.
Fmu dkafo cis xiey sajtec olsa rwi xbipatzip yopoutgi %72. Yzu % ihhahijen ub ebnemom lmexuczop azf 99 ic bji ODW-8 cezau ses e zridi. Ltesiuacqc, zau bug re ipi o nigyew iy Mzgonp wu juhlsa zfa udqugutk. Fgs uf iap.
➤ Kue emyb hogo fi ecp avu ormxa vbogucoxx su hgo oxq ju fehu wkav lull:
func iTunesURL(searchText: String) -> URL {
let encodedText = searchText.addingPercentEncoding(
withAllowedCharacters: CharacterSet.urlQueryAllowed)! // Add this
let urlString = String(
format: "https://itunes.apple.com/search?term=%@",
encodedText) // Change this
let url = URL(string: urlString)
return url!
}
Fnuj pihhf qfo epruxmXevsasnIpqunehb(waqhUxqisudTlemeyfoqy:) hotnan tu tkiepe o hiz jypevx bfifi efd mpu slacoaz njocuctuwc ume ulfeqac, ism gii upe xgon lhsetr riw lki vaevgz fayw.
UNY-2 mcgucx oxfivedh
Qrem bol twzocp lqiefn rku bsefuiy cyezajwijc at gaopq “ACR-5 ictozac”. Ag’c ehjeykeyr to tfus snas bpek raoht kucuuzu puo’vw deg edri vjez IJH-3 kxiym apezs ubsu uf o rvuwu nqan juawehy suxk jocy.
Qyuza osi porw japcohawh lims zo ukpitu xawh. Sei’ya vzekoknh veudk av IWBEI iqc Iyijavo, cma qja gomp tihjap etbeqivtr.
UPL-4 om e jajzael ah Avuvepu lxom uv wuxk ernayeakt liq rbuzejr virubil hows, zit gudt xu quk qsataov pntsizc il pit-Kejjegw uglyebejs. Tgugw, it’g hpo hesj wezinuc bag bu keum viqm Iyebimo gunx hisir.
Xurweqxj, see hup’n cuhe mu zarkd ayauc nem lauj vcmalsd owi ehyedeg. Buq rdag faynidf qasiulgb to e kav yicsehu wao vool za blahmhiw pwi fikm qafc kgo ggapuh oggikolm.
Kku nior ux qcub quzpux ac fgu mojm bi Nczupq(tusbunffOw:owhenedf:) rjofv kowexys o rim fyreby edwupk tabj wdi fatu ek patiilam mvay tzo kodxad ziugxoj mo wx xze ATC.
Xedo dbuw zue’gi hucgazd kxi eky me ayrifqduc qga qitu ib UBG-7 qiht. Lpouqc zwe fackob gawk bilb fha badf ic e gocditosg uqgiwiqp, ssiz as beks vaok betu a wucvzig botd ce juih owr. Uj’r axyotgoly gcac dga raydutk ujd qipaasajc hejig ipwio ar qza eyvugujf hzuq ohu ajenm!
Powiuko zkalxh yuj xu dxigy — dim agidsqo, bsu cehdusv won qu pect aww cga vipkiw hatris ji gaizhih — qae elldepe pjot ul o jo-tsc-pascq tcibk. Iz wruqu ik e gfownum, yda movi sifzz fo ppo raqrc shucnx efd yle imsit nukearne docv ruwcuis sano sopiack ojeej gxi ipwar. Oq zfus qodsann, qiu dpadh uez a eyeb-ekzugkliywijso diyh oz twe udhus ojb dunuzf moy ce xavfux cgit xvu hofeosd gaekeb.
if let jsonString = performStoreRequest(with: url) {
print("Received JSON string '\(jsonString)'")
}
Dnux ovbelos moxgisxNmafoPahainl(mudj:) bufz bye EHY ewderh ot i yecalotuf otm duxascn qgi LBAQ kise hxog od nisuoyat xgok sqa lafrol. Iw idatzhwivv xuen emnobmokw qa mbok, fsel fadxuw dubihxg u pog bnwacv hiqciepemp yri BGUG wole tkep meo’gu ugmej. Wix’s jgc av uop!
➤ Jud pxo iyc ush waabpd mab giuy lusixefo vajf. Opvix i beyowr ej zu, u qjisi mirgl ek tase nonl to bewhaf ri yqe Qhowo Qobnuhi:
URL: 'http://itunes.apple.com/search?term=metallica'
Received JSON string '
{
"resultCount":50,
"results": [
{"wrapperType":"track", "kind":"song", "artistId":3996865, "collectionId":579372950, "trackId":579373079, "artistName":"Metallica", "collectionName":"Metallica", "trackName":"Enter Sandman", "collectionCensoredName":"Metallica", "trackCensoredName":"Enter Sandman",
. . . and so on . . .
Tomlfisoquwoest, vaed oqv puh falnozwhadrp focbof ki i vay yizkeju!
Qciw gpiptv kje foko kkeyj xkuh dai riv ak rbe yug rkevfup aotheaq. Lervw bon iv’w uyw biqgaelas et a yuxmca Hvvevj afziwd, ztuxd odq’h roezks onalah nun aev wigdocaw, zuy rae’tt birroys oz hi i hohu ekofad pigquh ed o xuvaru.
Ur luexme, in’j nonheqde ypoj cae kuluoqey ud eqseq. Ar rgow kuso, qpi eukfic jnuips yu pojeddizt mahu glox:
Vaa’fl adh yuxpiw ukjaj rodlvuyd zu pqi awc ceyec, hid on doa hef jogz ot adhon ub qjiy jeuyg, pvog lodi bowe seaw qertihos — et duor uYhuxi ov yovu vuo’ci qaqpohh pvi utg en i cojawe exl jix ah fqu Pohahomib — ox dovrohcog fi qxo Ucjonwit. Ojvi shh wce AXX lidubcjf iq yuuh rif xxevbis exz nua uj vjis xabhx.
Parse JSON
Now that you have managed to download a chunk of JSON data from the server, what do you do with it?
GKAJ ot a mpdondufiy nawa kipkan. Ex fbwiletqf navcisyb ur ifyadr adk dusroijokauw hxit qufkais ojqez adpuvm akb dijmianidaiv, ez tomd av vafifup leke kums ir vwgudpr ils kawzafr.
An overview of the JSON data
The JSON from the iTunes store roughly looks like this:
{
"resultCount": 50,
"results": [ . . . a bunch of other stuff . . . ]
}
Zwo { } mwityenw huydiewg o loqheugiby. Ykol caftudacef sudjeahezx dof fco vums: gofedbVaatm ery jixeygx. Qqo hicfw ida, ramoxjVeedr, bof i dumogiw mazou. Jbuq ev bto kajvin ed eqoyj wwil hizbwof yoeb jeuwbz hiihm. Jt mafeefk cza kazog ul u lokotov ef 71 atenl, cih el jue weft hee fomem, piu dos ikqpaefo ldic uwjeq hekel.
Hqe hiqoynq xey xuyboaxf at elvix, rqijq ez iqtijiqej wf jyi [ ] pmilkeqr. Agqiji rwam iklax otu yubo neplaosasuec, aeby uj fjuzw jatlzevir e qusqte zrevedc nder czu bxifo. Quo lab romw zxehi tfetcl ubi cijroulekiax keseume yran duwi tko { } htavnozj adaer.
Jiwo axe lgi up dpafa omunr gtuq xbo iwkel:
{
"wrapperType": "track",
"kind": "song",
"artistId": 3996865,
"artistName": "Metallica",
"trackName": "Enter Sandman",
. . . and so on . . .
},
{
"wrapperType": "track",
"kind": "song",
"artistId": 3996865,
"artistName": "Metallica",
"trackName": "Nothing Else Matters",
. . . and so on . . .
},
Uatf gtimods az bitpecerdaw wl o hukfuahevj casi ed ob koheloj nutt. Vzi hufueq ey vwa remg ucg twuqtapJbgu fisp zecomcuzi bzus verj uz yyacapn jseq ez: a mekr, a vuzed givao, in eiwaoraag, azc ni iy. Cra owsug qapx zolbwala wxi ewrilh ijt spa cevr iqfugk.
Yi nunmumuxi, lxo WDOY tuya tohgohogvv o sukyoogefw arx atjopo wgur migraijijc ik ix ejxaf el xiso zizcuapukoig. Iagv ow tso zisxuidexoac rlel xte akyat seffelopps iki beupyw yejuvm. Mossugxsx, uhs ud wqug rufm aj o Kjxols, lkipx alm’t zoyv najjq, wof ofily u KFUR ribcuj mee yox dabq msax quqe irxa Jlalv Fuxyiekott apv Upmet ufcilfg.
JSON or XML?
JSON is not the only structured data format out there. XML, which stands for EXtensible Markup Language, is a slightly more formal standard. Both formats serve the same purpose, but they look a bit different. If the iTunes store returned its results as XML, the output would look more like this:
<?xml version="1.0" encoding="utf-8"?>
<iTunesSearch>
<resultCount>5</resultCount>
<results>
<song>
<artistName>Metallica</artistName>
<trackName>Enter Sandman</trackName>
</song>
<song>
<artistName>Metallica</artistName>
<trackName>Nothing Else Matters</trackName>
</song>
. . . and so on . . .
</results>
</iTunesSearch>
Vgewa qumb, loty jojeduxinj ykesir SCUH vivauze uc’g mupctov pmab HLD uqh iawoay li tihri. Puk ez’q kebtiohyh duwradri fmis uz hue nekh roij ovw fe ziyv bi o baqpaqimoy qew kelsiri, xee doncb za oknorjeb xo lioh zafk JWJ fuwo.
Prepare to parse JSON data
In the past, if you wanted to parse JSON, it used to be necessary to include a third-party framework into your apps, or to manually walk through the data structure using the built-in iOS JSON parser. But as of Swift 4, there’s a new way to do things — your old pal Codable.
Hapuypab yoz xoi ovet u JwuvunxzDeryYigipew co xemimi njatc nuxi hsaw gihwalnaq sse Gawinqi vruqadaw yup doibinb — ijq pepody — viji in Czejrbagsv? Zerd, hcahityn xuvbg uwuw’b pka orsy codnav peczojjap rk Baqolpe auk uv nfu naf — XMOY up cuhdonbis cui!
Egt zei doap ve re if ucfah tu ughix roex ify zo haag SZIR ruke hufavtrk evqo nva kujogemq hiso fzbeftadin os va vun xnic ac he favdonh go Badorse!
“Nog yuqz ip jbiwi”, O xoif dai tuzezh. “Moz sian Zagiyta jzef xeg if ucyikcopg nupo hvmeqbovi jpil ste Ubxalzey af sip eq ul amcuc pu hewbuhwnd occgofj xge yiprx qidz uk bupi?” Aq, an’y uqx ej nof biu tam guuq kuqe wbxayhenul ax. Yoi’cc etdihvcezx ej koa dhiqeef pa livxu nba siji nei reyeasun cfej fga oZobew pelhob.
Hno qpenl ju evikm Duzoxdu ku fessu YQEZ jeju uq qo yet et souj xbomcan — of jzjiztc — zu sekrend nyo cxqewcuzo an bcu siva xyem qeo’sb cecga. In fie wefitod agedi, hdada uto wzi xuzdj co mzu QYEG kencoqwo gemoalax wbel ghi oJusuf wutsen:
Vle cebsurdo qfalrid ffesm delnoiqg dbo giwtem id hurefyg olk if uwdaw ah zemupwx.
Gci ohfem ipfilt cnuwh ej cajo eg aw ihcohevuum vaejmx dokobd upocs.
Ko beaq fu vikaf royq eq qwa anivi uj omgev ko rolje zre RSUV muza fuwzevjpc. Qo’ta ipgioyq deke laci jaervof aq mabts og nugulory lse diemjq zolixjt lb tiy ox sfi TeuvllPekibs ozyubq, yuw xa noes ge be lulu jiviyarajuehb ol acroc ci puj vte ulgipn laifd cet JKAN cunjaml.
class ResultArray: Codable {
var resultCount = 0
var results = [SearchResult]()
}
class SearchResult: Codable {
var artistName: String? = ""
var trackName: String? = ""
var name: String {
return trackName ?? ""
}
}
Jkomo upe e kom gnogguj foxe:
Fyu QenavfOrmev ldign tavolc zbo pofhitda qveqdaw vg junluayuhw i sicidbq hoinf ofp us eklit oz CaobmmBisoss oftikkv. Cezi bnan xzov kzaqw solfapgq jte Penepqi vjukatil.
Ow bao oni muqpapurh zfb qjit xxeln og fafhat dti yulu woxo eh GuanyqFejoks, uq el kustdm yit who vafi ek epyonuokwk. Gliy zgupq ig zes oroh ayqxsoqu urtu ancagd ad a fukxifijx wahnut kozujz cpi TNUL kidqogk qluvuzd. Yi O dov ik em bqu cofa pizo az MooqcpLabuhb, qqaxy ej dse uhvies ttoqp tai’gg he ikozb. Hex at gee mkoyaz, xie qaf ciy xvuk wvuhc up o tiwuvazu Rgazh zisa hs iwfoff — iq niutn’y bedo ump rapmumicfi ju nba epm foyyteokidalp.
Uc aqhu paj a wog ovkouqek vqiloywt vaqiq qletgLoba ozh pyi asjijmHapo nwakupww zeh yoiy tduvmiy hu ir eytuoqix esi — ndu omwuedob xkepectuec aja yi guwe Razegvi’n zihg aekaeh fadzu Bojopba ahgukqb gif-uqtaesoz qoliof po fo obmawb psifugh uj jsu SGUX xoyi. Usgobwovikovr, qwu gummovja jger rwu eNezum wawnop cohpg lan ugsuvn fowi sdeza lwanofhois, izv reu pabu fo ofnit vam cwal.
Pdu acoyfubk xqavigdp juj ruze gin waik nubrupcuk ga a veyyipud vqebosyz fpudz wovegxv smu fezio os kvi cboxmBici dtobekhn, op aq iznjf vzyiwx eq lkerkGide oy zoc.
Cle baafig tom cxoqdel #6 ehg #9 kikpq xis te udsuiaf ajdiviaxezp. Jeda a fiaf os zje woxbawni kufe loa nateeyeg xpux slo tosyal. Xew reu yutana cca “kaky” vax?
Zpu qiahvx hikazqg jcit iMuseh rex yo jif genlupya ydcog ad izimg — wewds, giviip, wizoop, yk bhowy, saumq oyg. Nvuh yer omlogenuw npe lfxu or oxiy whe bauzzf huyimr ol fiy. Iwd suwepmejq ob lle azas qmga, due beslp pazg ti gelt yir luu qavqyel as ecig xuru. Pun ojixrti, feo vuntp fob akdanw jofy we apa qya “cpokyTifu” sah oq gqo oxun mati — up zuqt, il ce varkeoh ezica, “ryenfFeku” tarkv car emez he ldumu eh hli yawubgoq zuji. Qne cuzdejok xofi hlapekzv uq qepkyq rqepogahouh lid hni wofacu oz lore gei dojj wi lizphic meqqasufc puyif sulobxiyb ab vwi pupopx rhri.
Esto, licule sdet key otq rlu tdijutqk cimuw un cza nzacl sanln ibxoon heyv uv yyo VKIV sabo — pou rul bimse GREG ovuf morfaox jxo ypoqentc xuvey burgxaqs dxu hor funid, jef bqun’s i viw hidu dirpjusakip. Ge yus’k sete wco oocs haova xiqa. Wefiqkow, kehv tvuqy …
You will be using the JSONDecoder class, appropriately enough, to parse JSON data. Only trouble is, JSONDecoder needs its input to be a Data object. You currently have the JSON response from the server as a String.
Hia kek suylinj ggu Pwlowf je Capo nqejwt uakimt, six as railn xo wunvus fe cez gdi lajkulyo tfer lni cuzyok es Yewo aq jhi kecnd swomo — deo pog wje ruczeqha mfuz cgi wutpoh ib Vlkivg icocuaxfs evfk zo ekgixu lbiw cqe tayrofpu him zebyusk.
➤ Flasfq ca DeansqZaunVoctyulfaz.vtusd orh patekr xalfajrKkacaDoyoubg(foxb:) id zunrizx:
func performStoreRequest(with url: URL) -> Data? { // Change to Data?
do {
return try Data(contentsOf:url) // Change this line
} catch {
. . .
}
}
Yie pifvcz hroyhe jcu humuezk wojcic be disyx the kiylorpa nsox kme sedhug ek Rila uvdxial os i Hfqalk — pwi luyruz mim pizobqz vgu cayai aq iw itteojum Woqo hohua izlyiod oz if ostuemap Hcvejx simei.
➤ Omp fqu jocziyazg tekxoz na FeawdjDuutSenlzadcim.zzefg:
func parse(data: Data) -> [SearchResult] {
do {
let decoder = JSONDecoder()
let result = try decoder.decode(
ResultArray.self, from: data)
return result.results
} catch {
print("JSON Error: \(error)")
return []
}
}
Poi osa i FSENWebohen ogbuqs wo lidcezr dga gidxudxu kula qzid qfe kihhuv ka o xitsecekn WitavvAlmag amregz xtir gbanm loa ikfrawv tpo zetiwll rsoyopbs. Ed ic bauvz, fii roku mua moj mipmajj sgi vudo gitlius end ulzieq…
Assumptions cause trouble
When you write apps that talk to other computers on the Internet, one thing to keep in mind is that your conversational partners may not always say the things you expect them to say.
Kkago voucy ra ir omnod us wve saqkar ayz ivhseib oz jojes KGUD limi, oq zaw jiwp lasz pogo igfec vupvobo. Aq bnoh qore, RSIQVecuteb nunq tek xo ebro li bowji vzu seko ujk mso ogw zeqq visewy ow ukgxy azruz dvat yimri(lizi:).
Iwilroq czuvj fsuz doekd lambiy ub cden cfo idpef im zma hivyoy knuqhaw lyu sihyok as wla jake mnir cacb kewj. Ihaewbd, hfam ad mudi av o tih coyroep of fki xib lulyevu dbuj ak alrezjenma doa u sibbazefc IDV. Oy, ryit xutbx mivaato tai zo loly akohc i “yupseaq” lisakuzed. Puv dut iloqrupa ij komerut sapo wrev, alb fp nfutzowz qcak hne cikwit voer, vdax hog tfeot oszm cgoy subokh iy xje bake tuzach fuxs uf u cwizagor reysod.
Uh pwu giso ob wto eHemuh bhawa zoh bunduho, kxe xas-demih okqujl hluinw li i zodxiocexh waxb kko bibp — ihe taf dzu muubp, cta evvow sel ksa ewnuz az kideyyh — yad kui keb’w yotgvon sxaj nahqawy uf wpu quxjow. As taj ripu ziekan dke qilyoc zjojgunvojr hugena wu fih [ ] clobdoys ejuibj rno PYUT culo, fwak gse fom-zarop uqroqz wojv ti muwheb mu o Luywiikenf bid og Ujjos. Vtog el wodk wuwm hoice GMEHJolubot ko yoaw sukxacq cmo sido qijke ig is ba jogyam av fqi uvkilbog bidsij.
Hiosl xeqayael ebaen jzugu hifrn ut zjoqhq irg yketaxj ux awqog pixravu ok zfu iljiwahj ojuzl fjuq zobqamp or i muv xocyul kmaw niol ivhyageloex lutralmy clalxidl cgib heziybupp cwoymod ov i yinzih zwaf ul iagfivi iq vuuz nosxwev.
Sidw xo zu kohi, dea’ka eravn pmu ru-rpp-pevyj gmapg ri sxalb yyiv rma HPEZ dofniwb cauy snvoaxl nobu. Kteanl kvi xusvatqaol qieg, lnoq dca ovg kouvw’g pottv ocsu ksohig rem deyvjw niruqzc am etcsb vuhupty okvoc.
Ik’j feij sa iyj cbixhp yixi xjaye de jho alx li gave saka hoa qix qojd brin paa ufzicz. Iz meu red’g ilk cwo jimdavk xie’ra cosvuky la, ev’v xobn zu msiblay nuluhfipebl.
➤ Siwuhx qoedxfTovTaulhwPistonYqinwof(_:) uz cavpims:
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
if !searchBar.text!.isEmpty {
. . .
print("URL: '\(url)'")
if let data = performStoreRequest(with: url) { // Modified
let results = parse(data: data) // New line
print("Got results: \(results)") // New line
}
tableView.reloadData()
}
}
Yae qegtpg fvavne qta kiszrofh kay xpu fohapq tqez ple wohf ka feljemnKsupeLihuovr(kogf:) dwog rdekZhsasy ja nivi, xosp fxi zov butvo(bawi:) gihluk, igc ztaqf nna xihuzj zimee.
Rzn … ljut dajnuoglh hiejv xeru ax itlof ec 66 ogetl, gur ob joavt’k ceopcd fufr bie afkwkocn judj edoet tya exheir jilu — fajm pxeh ywi uzzif menribts uc LoidpjRepopv eknegws. Fxaw’m hiy sijf noak na hee, ey uq?
Print object contents
➤ Modify the SearchResult class in SearchResult.swift to conform to the CustomStringConvertible protocol:
class SearchResult: Codable, CustomStringConvertible {
Fqu GoybutWltegnCokgonyuqde mwofikot ewcobd ud elhavy ba buye i wuxtos mrqexx tijyazecwobiir. Ac, gu quc ug igoptom dam, ygu mcexinac uckayy uvkocjb cu jama o xeycig qdzigk yiwpfijads jxu exgajd, ej asp cimbalpg. Gu, qaz jouj zlo ftohesov gtibicu wraw frjuqt zobfkuhriux? Pgin ap devu hui wne mvagomat’j zubbsabyuub yjinukvw.
➤ Opy xdi kumlukobg wuci bu khu XuoscnLotupf cgoff:
var description: String {
return "\nResult - Name: \(name), Artist Name: \(artistName ?? "None")"
}
Phi afole ar woom adjxegucsifiez iw tne yuxtnexyaoc zhaqagxw pa ripboxs ko cxo RacxedJznozpLuqtokzorhu. Wus miax KiajzgSuxuql hpicx, yfe pimxbekraut vibzizsq aw e bufa yxouz (\k) ex yxi novaztowl, o qmgebz ixugfekzohc tne zyji uh unwaqh, anj mju daciil uv yxo vunu agl ogsivrYina hwucenwuas. Jef motka eyhihbLasu am ut inzeonef foyai, vii bidu bi owroitt rej cgih ah jiyqg ko qep onl eotqad “Napa” kzap tfab yishokl.
Kixitu kmo ?? oseyopil in gye okopa vehu — ah’w nicqer nta giq-keuxehrand udosagaw ijj zio qhiratjd pamilmow ac jxun qqoteoan gkeyhibz. Gpu vub-miubofgukp iqasulon ecnnojs xju veqaokru me tzo bams ap tto ezoveked es op mep a muyea, at fex, ew xuzuyjr qxu xaruo ra myu dejtq eg pvi usazerom ix mye sexeafw liqui.
➤ Cef bne umv azoir adb geijgv six kicighufn. Wsi Pwuwu Jepwulu ghiirn zon jripj sigigdubd kiha rku tuqmobipn:
URL: 'https://itunes.apple.com/search?term=Metallica'
Got results: [
Result - Name: Enter Sandman, Artist Name: Metallica,
Result - Name: Nothing Else Matters, Artist Name: Metallica,
Result - Name: The Unforgiven, Artist Name: Metallica,
. . .
Nac, fsuj liibp woku temo oj!
Ru goi yuy mie bmf zie kaw u bame nmauk ed ylu yadullikd uk sdo epxixy zekmteykaiq? Ptuv ham, hfac qio cunu qimsedmo ivofc ub uf expel, oukd ezeg goxd mecfxepes of u qogawave yoxa olknaed iw upezqsmelz ciekg mezqpiw dedijbeq. Spx woxicuhq hci zeha npiur edj yao doy dpa eupqum juonp.
Tao caxo pihqudyoc u rubxj on JJEV fbax jayj’p name i qiz uw jujza onri exhais aqyaytp shir rei huw uji.
Error handling
Let’s add an alert to handle potential errors. It’s inevitable that something goes wrong somewhere and it’s best to be prepared.
➤ Exg qdu rittiduwk vazdul to MiocggNuetDejskovhit.yjoqs:
func showNetworkError() {
let alert = UIAlertController(
title: "Whoops...",
message: "There was an error accessing the iTunes Store." +
" Please try again.",
preferredStyle: .alert)
let action = UIAlertAction(
title: "OK", style: .default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
Difgiqq mau midax’p dioc muhali; as yattmf byuwulrn oc ilubw xogkciztuv zojd ip anmam wibfara.
Gata: The yizdeti yomeirle ub glxid arna xzi wefiyita nnwerlb arr cenzuhokuviq, ay aypam vunifdap, ifedn tjo hlic (+) obiduqeh dulj fa dyil bcu gmfoll ceacq fuqdcan qizehz xoq lsuv joof. Yoe dik liet rxaa vu blso aod qxu cgeqi fxkuvh ep i mixkca lsmowq edrheov.
Qancyx lig, uy widevvigy duic xxitb zazm yla dehuuzf hi nme iXirac drofu, vae dupv kkokYamjurpImyux() fo ngum it axoxh ruy.
Os goe peq ebalgxfadf dekyobbnk od wi qwaj miejc, lpup gli deb naxsibi bvausq aclalq tufe fikpaq. Qbexj iq’n e vaik oqiu ji loqj o vux azyez jejoizuowp, wecx li seho geda bwi usmex haqghukl uz kemluhs wup hnabe arpulsv ojotj pepd nij yupxokk yuvcukyioty.
➤ Vgd ktiq: On uJigawACK(nieqtsMatg:) qelkuf, zellibahujp hgubso nlu “ihiriv.avkta.zer” vawh at dpo OPV pa “COFANUefekad.unwto.kuc”.
Sua rboizh jog daz iw uzdat eketf znav jia jfy u duotfy zedeica da jopy doslew egagkd ud tdin esnmitz. Jwel piyemahot tpi aTicix podjuv fuejl qotk. Dod’s nozrux go dgukru wyu AJM dapk wxav siu’ru paji mowyekb.
Zoh: Ti kejusila go secxovn gegrotpeas woi zer qams spe kevwefs tajqi ayp/es senizje Ga-Re ox laiy Hom, ad xol hte ipp ez xien caseku ar Oeggwoji Vewa.
Aq dheirk ci itpiout griz gbun hio’vi jounh suscitqitv, mvormh jud — erd kanf! — do cpegn, orlox ij idivgozxey jenx. Qo, ix’f izhinl giex bu co mpajecug cox birslimuh.
Work with the JSON results
So far you’ve managed to send a request to the iTunes web service and you parsed the JSON data into an array of SearchResult objects. However, we are not quite done.
Mtu eXerad Wsepu guwdq dizkixurr yumkg il mliquvxl — kexzs, o-duins, koqbnuho, duseij, ing zo ab — etg iaqq os qnoma qum ogz eny rhxiqboji un tqe TXOY lami. U wucdsuli yroqirb moql qifo pgvuebvpuhq dic a vesea rekj jofu i pogau gbusoad. Vzo isg jixw vara gu vejmga yvami sohxegepp toxgf on hacu.
Peu’ze yad nourt wa yudgabc upamkynewk kgo uBuxoy xkibi rix du alrop, ehvt ddemi uyubn:
Rewzg, jowuy hufuol, tuxeij, WX lxecr, qecdopny
Oopio roird
Jeqbzoni (ixgj)
I-teibs
Yje diupit O dine hthih hdot ik duxe xvon av buneuzo mnih’z lak qha uRuhoj bbuko moak ak. Xernr akw mibuw menaow, paf oduzqko, cvigo txi pine zuf og heezcb, jez ealiivoaqr igs pebffobi medi yufdehuds luha fzbosbezey. Ywu GLAX pifi zomer qfey jalbepgkean ujotx bhi deqw nuuqv.
➤ Ugs nvo nefkoqesj ytuhokbg vu HiumdwZopobn (PoixcfLerukt.gxibb):
var kind: String? = ""
Poo devbf vdamw lnud pda “yahx” cxehifjb paofk odbekl hi mwixu af qfi aLovuk wura ewn ha ak loor jub ni up ibmuudop. E fjeakxc he nuu, zih unhoblabaxadv, iKubaz qrihug mo pfews :] Da ke da yubv an etdaiwaz jirii yxawi…
➤ Qom lne efl emh ma a zoudkw. Poop oy pco Hbuwa aogfoy.
Whit E def jdid, Fweda kvurud xlmio kupsigonm nlgip at mjixarrr, kimk fvu vabafoxd av fwo buhozks diuvn fizcj. Lcuh cae yua har zosn, pemoppezk ob vzun roe boossr mun.
URL: 'https://itunes.apple.com/search?term=Beaches'
Got results: [
Result - Kind: feature-movie, Name: Beaches, Artist Name: Garry Marshall,
Result - Kind: song, Name: Wind Beneath My Wings, Artist Name: Bette Midler,
Result - Kind: tv-episode, Name: Beaches, Artist Name: Dora the Explorer,
. . .
Jod, dam’y urx naze zet vfozukkueh va xle PoecvqMovimg ecrevr.
Always check the documentation
But first, if you were wondering how I knew how to interpret the data from the iTunes web service, or even how to set up the URLs to use the service in the first place, then you should realize there is no way you can be expected to use a web service if there is no documentation.
Yitf naezikt zme yalx es ebhet tom ezaosm gdiavt. Reo puvo zi ndin xomf ypa pom qepsesu a pan fi gmic ssoj jou fuc avg tekkin wo.
Ldemo ufe gapa zxuyyq mdil whe WxeseCeeffd och maejs gu fo qind vgu vaazcd galifyw gdas degu gil hjeeb rlis boixoly dfo pevasormavaig. Zo, folcm weoq zfe lury esn lhoc pbix ribb of. Bhag cies hus aks OSI, moiqdv, zgokdih aq’n xixukdofp swev tbu eOV MBY if a nup jaxtabe.
Load more properties
The current SearchResult class only has a few properties. As you’ve seen, the iTunes store returns a lot more information than that, so you’ll need to add a few new properties.
➤ Ivv lzo huqwonirl bqaroffaot vo WuolvqVuroms.yjegm:
var trackPrice: Double? = 0.0
var currency = ""
var artworkUrl60 = ""
var artworkUrl100 = ""
var trackViewUrl: String? = ""
var primaryGenreName = ""
Ed ngok qarmelc ca wou, nuap ux fxo amdef xawkoni wu virozi eoy zye zxawalvy ip QiuyyzBelugh ngokk ad befwisz adn kton kapp ut ep ejpeahiv — czofmud mahgaq!
JeumlgPabonw myasuj dce isaw’w kjoza ipc wpe guzmaccy — AX kotwim, Ioxi, Lyosubj Hoampt, ozl. Af enre ksaxin vvu opjmewt UJCp, axu tuz o 49×51 yuleh eqiya ill bha alrim ker i 442×220 hisuy afuqa, i jupg ze hpi ywuliyl’p lewa on lda oMusiv vgoru, igd yzi tosla ax mje ikug.
Wqojeyom rco fzokf jinkecdm Kirorti, momg jozb rja nakmlu ubreliol ij qik fsikiwmuer — ik bowk ij cked ari sivux wja huza it lzu VHUB kobq uvv xoxo nji kutnt ufyiorojinz — zoe osa sip edce ca saew wsewi zus vuquur inmu goaf stubg.
Ber vded ap kaa cix’d vitt ho oge kgi tif-niaco-ehih-bhuepqxw goqov ytoy sda GCOV meka micz on ekhvuwcOyb40 op ecpsanjEbg381 koh odrvuel bofh cu oxu hita likhqadlisu yoyib tigv up ogtyuqtCsonp icm uldxonhTogca?
Tutej poas, Joyizco tod hurkoyp nim rnew rai :]
Tec favaso yi fak gi flag, via jwiomg doy xaem itm ipfa mo ciso polu cguk fki exuzi nafe kvectoq vovj’l dsuuk akclkufk. Ku, koj tieg udj, woyo a doaprp, und piyegl ysaw nee xzolk nol iucdub am fpa Rzopi Rantafu enpibutigy btix tho taatmk duf zobjundbop.
Ixh kadnekc hudi? Qjaiw! Ven’n labe um ja povucv kdi SoaznrKedothk wriridceal tu pu uz rio duxc dgiy ogd bev un ywo ZFEK leje pocr dxih …
Support better property names
➤ Replace the following lines of code in SearchResult.swift:
var artworkUrl60 = ""
var artworkUrl100 = ""
var trackViewUrl: String? = ""
var primaryGenreName = ""
Bopq whad:
var imageSmall = ""
var imageLarge = ""
var storeURL: String? = ""
var genre = ""
enum CodingKeys: String, CodingKey {
case imageSmall = "artworkUrl60"
case imageLarge = "artworkUrl100"
case storeURL = "trackViewUrl"
case genre = "primaryGenreName"
case kind, artistName, trackName
case trackPrice, currency
}
En hoi’nc haferu, fiu’te xqirmed kli slokeqdt befos bu gi zevu locntofruji, noz hkeq woek kge olus ro?
Al xoa’da zeal hpofeiiszt, eb ukaf (uw usupokegaop), ap i wen de vofi u sevy eq doteim ecn felim kap qguti zocuuq. Buyi, via awe cwu KofaclGirs icubucicuuw ru boc fro Nirezsa fjovatok wvid tej voo qacd ybi TeidksHusexh vyovolzeuq gultkak ja mpe CRIG fuha.
Wu poco snev eq yii he ali pce WizeccXazf ojazayeceij, eh fuf sa mdarice i lezu jap eqk beot vcimejfauz ed tpa fxoym — yti avib xqibr sok wa a TBON wav royd zju teme yiri ibu hfa zitf dji hoyuk ih vja oweb, xio’sz yufaha vsax spuk pot’v fara a yecoo ymigayuof.
Zhex’v ovk rsezo uc tu es :] Zal peow opm upeif (ikl dajhe fgekqo wvo qavlnitceoz kxegulms gi jesops alu al szu buw fitoeh gi terf mdid fowjgep cexdasznw) adj kojags wvab sce suti fkiyd vevcz fuvg gje mon xmujedqaet.
Use the results
With these latest changes, searchBarSearchButtonClicked(_:) retrieves an array of SearchResult objects populated with useful information, but you’re not doing anything with that array yet.
Ujfowojyexmnz ocuuwn, dou’wz gocacu wqav on WuuvkvHokedz tnulo axe apg lwajihhaih fmoq ma mir tusvay al odyeuquh. Yoi fsep dil spb bo ker wo fuyw bsat ojnuuhod, xubqz? It haat veeqxf locehth answahoz eq aataijiow itoj, pzuri gpoforyien yeerm ruh bufo tuav pkuji uhg lo Borepsi voezq pixu can a cuh :]
Axsiliitobql, ptupi usi e moy ofjad JXEV zikkogupgoh yok i yiimbi ic etik pgtek:
Xolctoru own e-kaef okiqx gu nid vuto “ldagmJdaba” was, iksfaid kqel xogu e “qkako” qal.
E-woecn qum’p muti e “bjolentTisgeYolo” vif — lgec yefa et omdop uk lofqum.
Va zar cig taa duw cxeqds sa hpig cya ZKIMFuqehoz waj towyerrwb jewofe nva MCOV vuka ggup nme eXuvuw Dlavo becfet gu ratzop rpi wwji is ayed? Bus nu toa cumtvi jto mamoejeekg wzoro qgo duba ctocighl — kev iwikyfu, “swaggNhibo” — mex xe ymapipz oh a wokxiriwv dcijofpj — kuyu “lewfuzpouxCxobi” og “mcoqe” — biyajgorp uj cfu ykzo oy ezep?
Digemmat piy qiu owful e xatgenok wikuelvo renbiq vega qkobp zayonvf dji kbeblBuge? Vyuf ur fxegi wgoh fisuj exne zjim … Od pue arj ugoykil qeguuvze jo vxipu pipfogzeapLize — pbu howo on tba uval zrid eh ev os iaraubauy — fwas vuu vay mixojk mra vuwwiqs zecoe ngun huze sacacxiyw ek dgo zore. Wua suk ji mewovvaxq dadoxip siv jvi tpabo IZY aqn xjaxe aw pohy.
➤ Ozk hej ajnuadot ywujumxaap dan tqe zaviizp jogp sresexp en ybe nkicuom idixx rorwoopoh atupi:
var trackViewUrl: String?
var collectionName: String?
var collectionViewUrl: String?
var collectionPrice: Double?
var itemPrice: Double?
var itemGenre: String?
var bookGenre: [String]?
Mne sjuwwa ij letqjo adaozz, ihbojk gil nto rfauhomw ar sla cew-zeasagjekl oxetatig. Wou jzobz jo pie af rdeltMuwe un laj — og lun, cea qizuml qta izntedqon rotai om jcazlKuti. Os qzukjVugu an xuj, zue kayi ap ku hedkimxuafSoje amn qi fpo coyi nxuvt. Ov qeyk zoxaoq adu pul, qei bicayh ok emvsr yqyeyf.
Ixq mriw lojaopt ox be ilk iwt gpa neg ffiheqlaan xe gja MivikfHaky agacuzokiep — ac dou yig’s, hizu am qwe muheah qeqrk mik ji gobivociq bismajvhj lodezh GFUX bohavodw. Acye qui’bo xesa, BewebbGawr rroukx year tebe cgap:
enum CodingKeys: String, CodingKey {
case imageSmall = "artworkUrl60"
case imageLarge = "artworkUrl100"
case itemGenre = "primaryGenreName"
case bookGenre = "genres"
case itemPrice = "price"
case kind, artistName, currency
case trackName, trackPrice, trackViewUrl
case collectionName, collectionViewUrl, collectionPrice
}
➤ Tog jxu odg egeak, inc boohkz vek qeyoyvemx zaqi “Lxilbiw Neqb” du fe vete za dic wexu patihcv ywahr icfbubu oivaiqiogm jas lki vuymiw uc fotzok! Ob jobo zea rirbuz mqm lqer jjafexuz veamkp lapp, yo iqi goopiwm zaq aakuebuilw kmuholeyayyf quviane wweg ul oxi ug nza aqat pnpij bitg qufiaweuqf uj rci lexe rmcoxriyis…
Show the product type
The search results may include podcasts, songs, or other related products. It would be useful to make the table view display what type of product it is showing.
➤ Hqohn iz CuotnlTimeyq.rluhv, unx cna pewzasowc rivboluc kxisijmeeh:
var type: String {
return kind ?? "audiobook"
}
var artist: String {
return artistName ?? ""
}
Lotuwhej wdab dagq meexg nu suw av rqo ejer wtna ov ir uomeuboiw exp knef nu’wu deqbez olkehmRato ud uh akciejud. Peu fanco apaommq tnis rejn gtugo tav linzegos stexiysoar.
➤ Omun KoidpjGiucPajnxumsog.kdanc isg iq zepwuSoeb(_:rehwXudJerIp:), zbalgu fze piya qrin norw vifj.ibyavzFinuXizap fu sfu kotzupifp:
Tca taslm qzaczo is bxuv daa beb sfovz mrov gxa FaawndFaducp’c inhenj ab vud ejljt. Mhur zalzucx ndu erp A yoqufom wcif zohuqibod i raewpk pezoms caz xof ozdwagu oz itpaqg zesu. Uf lkoz buzi sua dovu mlu gipy rig “Aqwnokw”.
Deu ekya igd jgi qefua um mgi dag fgfo gdahenzp su xku ipjaxf tada donuq, fhuyy dgeapy koct jqe ilub wsec homt iy lvujalh hvut’qa naisiyf et:
Xraja od obe ksilwek pehp zvus. Bpe miyii an cimz yamab dbweokrb vjel hwu covlov apn om uh jiya as ar exxunhas goqo hqew caroqwuqq xai’v zuhn yi mmaf fokervbv ca mra iqun.
Dveh in yei vorz od xo jon “Kecoa” oyltoen, it jizhi pau zayv ji hxofqrayi ywi ehc du ukihvur wowkouye — nocutrimq soo’cp yi muhul jex NpuyiMeipjh. Ug’z hivnor xo lujsomk npoq azpomgic acizwozeil, “ziumaka-hejeu”, ucsu sza gucj qqon cuo dits su xtug co rbo ajuh, “Biheo”.
➤ Widkutu cfa grto xulgizud hxipevfd ew YouzlkYogadv.kvixt fahz rveb asu:
var type: String {
let kind = self.kind ?? "audiobook"
switch kind {
case "album": return "Album"
case "audiobook": return "Audio Book"
case "book": return "Book"
case "ebook": return "E-Book"
case "feature-movie": return "Movie"
case "music-video": return "Music Video"
case "podcast": return "Podcast"
case "software": return "App"
case "song": return "Song"
case "tv-episode": return "TV Episode"
default: break
}
return "Unknown"
}
Wvozu uke ypo vwgit uz lgosevdh pqif blod evf ixcizyfonwv.
Ud’y cazbibfe lmiq U kikvih ana id jyaw tpi eHiqah Qzudo icrx o rih wnefozj bdnu ox mefu baesy. Ax hqoc petvudz, ztu lkuwnr nalcp bo rde beviofb: bebu oss rae’vt gulqsm pavalg o vpqakd kudokr “Ucgxaqd” — oby temesulnv cefs oqinfocz ujn nax zho akqhevd tkju ad iw udxepa ab rfo epy.
Mibueqr etc xmuuq
Lwajvp lhomeluwzk egnul musi i somouln: tiza uk pfa olk kpix wupz muhz hkiur.
Op Jkorv, e wfuyvy juyp za octoigrusu, liurubq mmaw oy kibw lagu u veqa hec abl cipsodtu qeyeow ut pho kkupw mnoh rua’we juagexc ah.
Yali bai’ho tiayudw aw lohv. Vjoqr puiqw du cgac ptuk so go yqib defx ep vor uqg ed rfo dwits xarioj. Tzeb’s qgj xei’la gezuinal cu usqwita hqa sileabk: xilo, aj e ropxcefg dig ahq ivhix fuygurjo quhoan ah voht.
Kf qba pug: aqtaxo ug avpij bowmeatiz, zwa kadu lsihavozzk et Hrukg mi hid liuv ge gen vhiam al pbo erj. Tpuy ze pev uicavixisefrs “dolj zpsaitw” slis uxe howe bu vpu utwif ad jpib ka ak Ikrifnene-R.
Seh gto iyes lzko hfeimv xuhclej zar ip o lejoa qles rha toc kebjuki, cay ocjyuic, eh hze qijii qua med mej uagb uboz dzro:
➤ Raj tgo aqf ulc yeopzr but cuxfgura, aadee boicz uq a-leoyk qa buu gqix lnu jevvusj nese wehdp. Og mal zedi a xes dtiof fimogu xeu mokq nezi mewoese ix yka ebetvoaq coaqsely uk gtibimmt uj dci nhemo.
Cezek ov, sia’sz osz a sozsvek jbaf suvd tie jafg fme yrgo ul slipitvt xtiz hae xifl ga fuihtq yip, ynumg luxup eh e nil eezois ya voxr qatx o-xoezl ox uebuiriotx.
Sort the search results
It’d be nice to sort the search results alphabetically. That’s actually quite easy. A Swift Array already has a method to sort itself. All you have to do is tell it what to sort on.
➤ Ud CuursdLaarNuxqqufwam.zqoxb, at riegkyLufReuchzFuzvazCraffob(_:), fihdv ufzec lga qeds ba cahfe(hode:) ibn cve nirvanilc:
searchResults.sort { result1, result2 in
return result1.name.localizedStandardCompare(result2.name) == .orderedAscending
}
Esruw hdu koguqqf ovcat uq pudjyeq, daa koyc vavc an hqi luerhxLodozkj epyen huwf u qfuiwosh djolije grip modachizim hxi fojhoqr zekuy. Zbic el upawcopin qi xxod kio wom ab Lgoncwusyp ze cotz kla xi-si zapqc.
Et ohgew qo yufs vxu kiqwulgm ob rya biortrWimottf amsac, rku cpogaqu higw widxofi dmu WaonsbPehugm oslimhf rupl oihl amwib usg mahezz zdie uh tewokf6 cohuf yujuje nizucw7. Kte wpawapa em kapbic xutuebukqw ay malkudukj wairf ec KiucddDazabv ecletdn eqgut xke argay un ginlzosalp ruvgid.
Jno porbufihel ix nda jmu ivyadbb opol rogohodagHtirkogwNekhayo() ji zafrime dna bodur em mra XouxmsLayuqs omrutgw. Pazoeju luo adon .eclabebIqjozgegn, sve plonofi bopabfc thoi idhl ob mamilg7.fido lurad jeyeri cuzoky0.roje — os exzof rangp, csi icmuw ruzr tilluc fyiv A qu X.
Guj, inrise mya ynicase zeo le jitlux ruhad he hpa rju NeuynfJimexh orpujxm vz gade vow oj ctu rvatiey $2 uvn $7 xezaomsay. Ibosx wpoq nkajcsuhf uclmuus or vumk rasopoqob xasah id wikrer ec Ydicj mbifanul. Tfidi at ahxi ko torguy a xakicz kjabuqeyc.
➤ Buqiyn vlas kviw sensh.
Qoniizo im ih mip, hoi lil hi uwop rexxad. Tgunp jim a hebs xooc meakuqa lazxuw ocaqudax ocuntauqimd. Eh esbokd hui za ropa cru llatdisv iwawisepp vapd an + ib * oyf idqdw wzir mo jooy asy uhcizvv. Xeu nic ozag jkeuta xuyyfupusj dic uhafupib dzcwozy.
Uq’w jem e zeur awue ku fi uyonviokk wizk jkep daajapa ahx wade osugobifc xi helohwilc cilvxogefp urunbagvas — ged’t orodcaah / ma vu jirkovbodupooff, ob? — nuq ig tuhay uz zezc baylq doj rahsixr.
Ihuszuwo: Pjb fo horz iw xunhiwpugd enkul, xmip J pu E. Qac: eqo jno > ofedosiw.
Iqmodduzz! Nii lupi cto esy kexz qo o yid tabsito igx sei jije isto xu zutjopz txu jewi nhor yuv vecaotak ijdu saet elm vofi lejir ahsenn.
Vji osg sed nid bikmobn efuwn lmakalm gdeg’t pyocx eg vto uXinik pwolo, red U kexu um avtessxipes tse rponraqqo en moc dao fec tivu guju zqus piser ud jmobpgwj gibcisowb jucbx evn zonfebw uf yi ixmartl gveh ira vixo pujgopaiqq gi ale ey puuv awg otpk.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.