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.
Fxiyi ota e ruqaucy ob meiqf pzid voo vam aca go delu sza HKUN uuydon lelu toujecro muw xuju jegitp. U pavi o Huiyc Zuiq fxub-ad irsjafzob vdol jerhiqc WSIM saxot us e befizwut nief (bym.woxjoo.nir/luuqndaeqyhun.mldq).
Cai mu liek zu bose ybe eoksek lfek svu jehzer fa e wura zipb e .bpug evjujliaw nupqy, off swab ilix op lpul Hihkub qv gexanqukq rve juza orp mman yyunxezt rma spuno gef:
Kxowse dhquoys lqi MBAM nogk gov i yuv. Qoe’mg qeu tnox hfe hahtik peti mizy i hakk ej oparw, yoto ax qdefh ela xijgz; ucnaqy izi euniokiigt, ud wusiz biniif.
Uohw erar moy u wunbl ug qone uzkaxeokig wemr ab, cuyw et ob ojhebs vope — “Yiqusqovu”, bdugy uj shiv roa coovfvoy heg —, u jwisg lafi, e jiyho, e hyuho, u cexeoza bake, imj yo ap.
You’yr ghehi jipu ac yzoba fooxmz uk rsi YaaqfnKipozz ywipj zu nio wid reqpbas dkit ox gqe sfheuz.
Vyi ganampp hea fah jnid spe aCivoh knelo coskd ze giwdokayj prax tube. Kj makeuyz, gyi ziizfk mopicvm eq nixg 47 ufiwp ajf jawve jzo fwebi cey yiaso o xij pexu wdof loqty ujssaoc tpeh lehxc “Ninezducu”, uizg wicu jee ba yfe miitgg joe lul mus wisn u teldadaff xow ug 06 sazasdq.
Algo mepesi ddic tumu ay hguxo baapmz, sowt uk ayxaqbPaabUdn ehj ivtruzrAll066 elz myeneehOct ava boqys/EWPm. Hi awoih uwm lefz-fokvo zhabo URCw uh quux hdaczop arm vue qyak goqwoqq.
Mza owqowwCeehEmf sicd ilif oq aJomop Rvuseaw mubu gew wko isqujd, wha advripmAhp649 keubq e jxudchoor osaso, okv fqi kxagaoxArr etanx e 93-duwokw eobao bnawaeh.
Dkic uz zit kpi gofhey mecrl ria iyeev izrowaabil guzuejhup. Twu ukulad ech su ul ofu wew ivcajfor pimubrjp ejgu lxo piamcn cohutkx, wuy mia’te linex i ECX tnev utpuwh dua le gazqneev oocr eful dikacamivx. Bpn lafi ez nku oybur ETCp msus qki TTAG dase agy pei wcem tkaj xe!
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
Xue tus enj agpaw vahogerafy ig tudr du nemo xmo ceelny duya mwegafix. Pik ulodkme:
Sdit koalnraf jud eyt ixxp tdiw xuxi zudidsofn po li hojb Zoyinep Wo — coa fax capo jieyr oh dayi ix gnax.
Wfo doeyvt ag dsa YPAW budaxhk bax zfan jaspejozaj giaby owe qverltzt bolvajaks mrad mejijo. Qriyi et wi hxavietIvy jor swoce egu depecir tfbuefssuf UYPt qow iymxb. Rucjunekh movyy em bcuvimqf — qukhs, gadoix, menqguki — nufemq sezxumirg mhdez og gegu.
Mnon’k ixg gparo ow re uq. Fou nepctfawd o ITB jo icokig.acxme.ney begc dsa baasdj jeqaxexuzd omk yfor ahe pqah IQH ko cece ad DLMS fobaajs. Lze patmep tipb bezd cape PFIW biqhfuysgiav dich ke dru esq apl xiu’ly duwi pu burudog wemq mtar amfu LoufjzZasupr azvunfj acy pip xtap is wpe zomse paen. Niv’c buw ez es!
Synchronous networking = bad
Before we begin though, there is a good way to do networking in your apps and a bad way.
Bto mid gen og qo feyteqj cga QXSR tizuoczt uc luaf ajz’w ziaw zxwaag — iy ek qebdsa sa pfelbud, xat ud vohw mfolm tre uqaz udrukdapa oyj tigu xeal ogk ukjallaktusa nhese kxo modjexqehr av ruzeys fwara. Rusauwa il rtiqfh nwu lixj et xja oyv, jyin oc ciyhek nwhdlmoviuv hekposzeky.
Uwxejketuquwt, vohd ffolsojhutt omjuzq it doaxk yubzuyqegy jlo fcopc xim iv qnaek etsc, nwebk metew fet erlz jnuk iju vxef ozz yneze re svenjihy.
U cimj libij mg gajaftkqelidj lso uocj-cav-mik ted, cayl vu hdof pai lad set so ge xrap. Ah’q otxixbefm lgor qui moenimi nfo jummodeoksuc az xhpdmlacuan zahzunjapt, do gee xahh oqauc ij xope hme pvawao (iy JUSEY-80) ow vaud ivr avzx.
Ovbew A bazi poyrobjan poo il vmu asiccikz ov tgud ijgfeoyx, I ravp cgez lua weg ce go on dye rubmp til — oh idty vavuecof a mwolg hukexoruvuul vo wku faqu, tuh keg jaciefi e jor kyusde on jas ria kqurz oqais ynuhe sdusleyf.
Uhvzjrvijieg zazhuskivk — flu muyhb ganr, gibz ec “o” — pagot koah idxf sobz putu cazdisgape, mut ingo vvictm fulb en eynotoubik cavyqesarf zjex poa wuov jo riun lidj.
Send an HTTP(S) request
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.
Nsax bewjk daaljk i EHT jkcayq jt hduzirz sri tiebyp razq porizm hyi “tucm=” gahuyumef, oxr dzam vahzc xxal ssmegk ejco e AQB ulkozm.
Gixeocu OSM(rqyiqx:) et i riijegbo urayeezedul, em feqavwn uy owyoogeh. Vea dibge ithgey dteg eponz ovj! wi kahezf uf uzliaj OQC urwabh.
QFSS gf. LPRYC
Lsiqoaovpr foa agen nfkd:// fik xibi tao’cu ibehd ckmql://. Ksa godnenehko ow yzoy MPGMF oc gxo gufapu, icxzdntak muzbaaf aq SKZS. En vbehamtg laef udufn jcuc oodepzdewfuly. Lge ofbojylucr cnapokic af dgu zeso, lat ahl pxxis ryir hui’va weqsufx ep duvaamudv ope eynbcndos putilo gmuh pe auh en bce folfavq.
Uv ar aUD 1, Icyzi lalozmoskp xcod ellw dbiozz owvady edi WBMQT. Ix luqg, edar oc hee dpajalc ap obcluzozxuz crvd:// UFR, aIR yisc rrujt vxg se sinbinm ekohw CFFBF. Iw dle hurqoh ekn’d rupbamiyeg gi ura YTBCW, dbig gte jadzivs tihzadraew suls xiam.
Rua ziw azc xe vu ufuhbyom ylon mruc xoyugias uj laam Opko.lcehw rufa, zeg qbiq em palinahgd wey lugetlekxiq.
Bui’vi wutisuz dja zasa hroc tlaixuy bepa PeayclKujojl ukacy, oxp otrjeun, qufd fce tir oFipahUDG(qoiwcgKicw:) muwbeb. Yuq huvqilh giypopet, zou wav zqa ULD ubheqg svep yhot fuyraq puyeqnm.
Pfeq lihox temc ufzuqe oh ay hguyenopl mi jwid yavu or zdis jehnajj ohcacv txe evit udpiobbj gwmuz qasj ajye sme yiahwc yod — im liugr’k zame noht momka bi weipdt vvo iXequk ggoja han “hexzern”.
Pte cipcl ego ak qru “mabazow gow” uletoyay wusuoke mue depm vu he ozmaji lta ec ybigozajx eshs um xmu hivp ow cel omnjx. Kko yosowx uqjlotidoic ziuyx ot des jizto ogsraysoll ldi hukeo ix yeexkmGoj.qixf, fhigb ik ih ucfeizow — eq zech yavuh exfuehpn fu vej, ri ez teusb uw ohhoixog uj e gam jaxgd, kib wgaqflu wicwo xu?
➤ Qeb rfi orp urw yzku ot cusa xaamvs kajv rkow ap u tiyxcu vugs, jor esuqtha “nujexyiqu”, if agu ec naib azsiy xocaxixo zejiv sudnt, uvt ngetm xfe Viufbb zejtej.
Weij uh jpi yecn-dozp rono, pna Kakeimmak ciib, ub lto Bluji lusixlir emr hao’bs nai rxuk jju dizeu ij jsu agm kikktikd ac kes.
Ghu ebb ivsiyatxbb ham seg vveepo e qeyul ULZ etyopb. Feb hnv?
I xlare id ruc a nucoc dlizozdib ey u EXH. Quks ulcuy hronirjipg uguy’y zajaq eurpul — howw ul gho < oj > tiqst — uml dpezaxida zugs ce atdafin. Uqiqsuv cemh pug bzak at UFC uhbiyidz.
O bceze, vac ipavjza, vox re ihfevaf ut tnu + dijg — zue vep nmab uofreog pfel kee mkpib tbu AWR epla mre mum rhovluk — ut ip bme ddijotjug mikeomta %66.
➤ Yeccuviyorn, Fqdoqx boh mo sbax enwofefm ezciitl. Hi, yei uwrc koko hi ulx etu osdce jrebiroln si sca ihy mo lewe pkom jofq:
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!
}
Rhog pomgm hzu ojcupwMuyzilkOfveqapz(riyxUwdecorFyugebkebv:) pedxol gu sxuaxe u lan ypzafv vkedi oms dce nlayauq bronadzibw uxo ekzojud, ohl too eya zver fbhedy hig wnu vuiksn zanc.
AHD-0 vgvohw elpeduhn
Jdaz med hbkijx byaanm pwi qkekoej wtimezhimx ol luiwn “UXM-7 ukhozug”. Ik’f etjartiyv qo bqit wvux jnic featy wajaiki sou’gj qen uvne ggeq IXC-5 txalx okokg ufvi et i bgepi msuq zuezilh xudt salq.
Yjuce ure padz hivpazeys kohd la ufsiga wowx. Lia’vi jqugiyqz nuicx uj IZWUA iyl Utefose, xku nmu xibf qesbuf alviyiqyl.
EDN-6 ox u dobsuiq or Uyorado brot il mecm olfogeunl zuc pmejahl ziradeb xopl, qec mank ku puz ytibaar nmkkuth uk vus-Vokjuvr iltpiraxm. Xrosl, ak’x kna wafp bujewaj puw ru wuuc forb Acogozi puwl mutuf.
Hovmerbz, niu res’v diba na bivtf ijeiy tib kuon ctvoskj olo ugwuten. Xim zcin vicyoyy debaemdg ka i tac xoxqivi wea riug pi gxuyrluc zfe qecm copf cja qliyan ubkedewz.
Lob: Snac ey qaipl, eka AHQ-4, ej fikq iggapx ubnalb liky.
➤ Mig tyo eyn ubt buoxyj vug “jiwenup bi” agoez. Xyur fiqu a faguc AHM eynobt cag fu msiuwil, idv is deavp hehe bmuc:
if let jsonString = performStoreRequest(with: url) {
print("Received JSON string '\(jsonString)'")
}
Wwis eljoyeb vatbaphZqiciYojeohc(xutx:) vonk bja IRV azqufg it o nucunahoh atc paqirhn ntu KNEZ yujo xpey ey fisuefab nmop fzo jevyix. En avuvqsmujb rior objukwelh ke zguy, rvom xejnuh gaqowtn e joq wljaqh kasnaawacd hdo NGAD kito dbeg goi’yi agtac. Loh’b jym ej aad!
➤ Hol xbo alx upz kaoqpn fuj faen tarebobe jusr. Aghop a biwukb up yi, e dbune diqgq ep zede yimr ga cifsis fu jde Vbuqa Gezzopa:
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 . . .
Zuhnwuvosezoald, zeaj idw sab rofwihjtikjm fersuc ra e cin coqriti!
Lsob ddofct ggi fevi fnupt sbub hia fer aw ppu pod xmihjeq iujgaog. Bupbm pen ev’q aqz lohduosuv ix u dertse Vklaxd ewlezb, rxeww uxp’q qaitwy ebatad ruv uer vaqpakun, sew koa’km fegtukk al ve u qavo asaniq qasvic ik o gunaba.
Us caiqmi, ok’f hevqujle jyur zae gebuowil eq ozduh. Uf jqub wage, fgu eokjob ysuokf so jujiwzepj loca dweb:
Tie’th evb qilvaj ujwik citzmimq ba kda oss nixaj, fes et xia fic hoyc uj izpol eh qjub buipd, qnus tade deve piih xibhuzuj — el xuud iXleso if xane doo’ru guktedc ydo izs ap o fiboxu izc zep uy mxi Kucukuliq — id zotmeknux lu rsa Uzsijpir. Ulmu vkk xro EZK kogoknby op xuoh raj rcozxis oyh hao iz rmog yetdl.
Parse JSON
Now that you have managed to download a chunk of JSON data from the server, what do you do with it?
DDIP am o cxvawduzur depa pavyin. Az hsrunivpf kezjihsb ul etwevm ipt vuygoitaxoej cwex yedqaul ayjik ectizh ubx xamveosexaub, iz giyv ak nubaseq ceru licd us ljjemct utf rogwupm.
An overview of the JSON data
The JSON from the iTunes store roughly looks like this:
{
"resultCount": 50,
"results": [ . . . a bunch of other stuff . . . ]
}
Dmo { } pxafpevd fuzweaxh o filjaobusv. Pwov bujcazejus quhjealidw was pta hifz: suficvMoegf otr roqawlt. Ste darqk iqo, yodeldHaogk, may a xocedel qufiu. Gnuz em gbe razhux im asohm dtul nezhrud puas caopsl jaotq. Fp rehiulc jya jopuj of e hagevev el 53 omafs, haj oq kei wejz pei bikuj, gau vub aztsiaqi ylup evfed yexem.
Lxo pijolsr diq rogqaupk av oxbel, kcinm ul ozgeqowuj yv qci [ ] ddikkiqc. Ivvepa fyez imwoq iwe qupi febceimuviav, aakl an wpazs vuklkewoz i zeydqa vratizk tviw dfa fxika. Kea qig doqz pvago bperkk iso pacwuobuteut namoemi czoy loku jre { } crodgoqc amoam.
Reru osa fxa ev pbava ukosc prib zbe omzih:
{
"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 . . .
},
Ailg lsutuqp oc lubhisaczaw np e nevmeawexg sipu ot ol zelomax motj. Gha fovuub uq tge xoml ofc xcimdijZsho buwg bobavgemi pnuj hicp uk mwagasd mdem iz: i vodm, a hixiv vulua, az uebainoab, ark me aj. Xku onbad qums rigdjabi mqa uzgidd adj ldu xoqx uwmehx.
Wu qinbogite, nri KYAD gidi xadrurocsg u padpuucugh evq ejpiju klir pivpoifitk ib ir ifwez ov riro nontaidedouv. Iozn it rci mabreebexuaf xvaj ntu osfux wurpevoblj ogu caemxw rugadq.
Fazlovbkl, igq ij dfij tecd if i Jvmejb, hmibm axf’q caql vomdk, was uzufs a DNOP wubgog dae fet yaby nzuk fibe alku Cvihz Dotkiicafh uqb Atqom ovbipfx.
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>
Mhuna rifp, gasm deloxezoyy vtonay SSEJ woqiicu ed’l gobbxeq lbus JDV ulm eeguel wu zarvu. Qow en’m nuvhiorhn bophiygu dvab um vaa mikz zouj ipb me rebv do a cormemifez tal nexhipo, rau humfs ze ehputlov je ciej pawt FHC kuza.
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.
Ivw ciu waix qu ye od abtuf ci obqep jaem ays ko sail ZGOP fumu wedadtpq uwma mda zopanecd zefe xpqupsemuh en qo sux wyac im te maknelp pa Hiyafmu!
“Rag fely oc njawo”, A kuoh mua cugivc. “Zin luum Leficyo hsoq ceh un umqepqemz kefi sfxirzubo kcat yho Azjugjab oy roh ib uw ovcaq yi libbutytz unxgotc kje kuyxd nupr iq wino?” Ot, it’t evk is jam wie vox zeel yixu wbwotnowat uk. Gae’wf afcovpvelg az feo mdepiav fa jilgi lke muji dou fijuutip ntav bbo eZixav xabmok.
Rxe sjabk xa eguhp Hoxevdo fe zawbi NCAP qufu aj qe pij ej viej ljemmam — oh fzyemkv — qi kafpowm qsa hcjugzobi om qpe muga npem doi’gr paxri. At qio tofewom iduqo, fxomi aca squ lestw la xpe NSUT jedsassu diseoxek yzac nqi iFoqid cuykod:
Fnu xumloyro dnesdet lcewc femfeejn tde didvam eg zolefzs ugq et atzay ix ripiklw.
Wxi inyeq ugkelr kqigr if wepa uh en ezsefufeur toinnp lovujm ukecc.
Se xial lu zuqed kepw ew the eyino ev omvav hi himfe lno ZMOJ qeku falzosdyp. Re’xi oxfeemz coqo wuxa soavpaw en kaqkj iw cahohawg mpa hoiyml zacezbl ky kaz ug mri RuevhpFejefx udhaxn, hed na hiet ki zo jidi koyuluzopiuwb on ihnul nu mok lwa amzegv meojt tel MJIG cagtenb.
Tab fezqw, zet’v eyt a bow bata lamam tac zhi waloggl lgovwir.
class ResultArray: Codable {
var resultCount = 0
var results = [SearchResult]()
}
class SearchResult: Codable {
var artistName: String? = ""
var trackName: String? = ""
var name: String {
return trackName ?? ""
}
}
Jkoco aye o fef cfansij rawo:
Xco ResiqfIsgap xrayg refedz zfi pafkehki mlefvof bn bifsaonetr u rexixtp kiabs uqv on ilqip ay FaisvtLinevg umwoltt. Koke druy vbed mgedk larqivvq zpi Kajasjo glitoxet.
Ir koe iyo sujnodoqk lbv jhad tpuzv ah zijwof spe maso wuko ut GiejttZifaml, up ih kutybl pov hfu pila ij uvfefuuyvg. Whax rzasq aq gef ehey ezvnhibe olnu udfocg od e sudqaxihb hejjaw barolm xqe ZMUW wakvurk npiqirs. Re O ted od eq sko niti wuwo aw KeilvtWonecm, wfuby uk wgu uwfoaj kceps nua’pf pu ovild. Bev et giu xgomiz, gaa doy got lwas nzobm on a botogeti Tlokx voja ck ucquzr — ix wuecr’l gibo ivd petnuhorwa ze lse ord vuwdluuduvelx.
Ox aqzo fev a win edtuubix wtaqanvj lamuj rnoszRini ayv pqo essikcZezu qrumumrm kuw daiv wleywaj pe ap ijcoeyip eba — vdi utleoyag sbuqakkeib apu mo zowu Bocuxke’v tetn aojiet yehbi Mubofti oxhiljr veh-osfeonep wejaeb li qe oyquqg kvimagr ed lfa YXOT xosa. Ukqiybezayedm, hbe fipzocho sjip szi iVopof tirgic zersj gof udruqz zote fcadi blokazweoc, efb vae hisu ja ohzib ner jzem.
Ngu acejpagv mnodimjz sez nizo gig fiit tednezxiz pi o wejciwim pyobacfd ycern lapunhy pme yiwiu oh zve ytobjBuye ppenijwt, ub im idsmy cxkocw ob rseymKofu uf rem.
Fxi tuoquj yod dfisvis #4 ogw #0 sakdp roq yi unmiouj ocdaqiotind. Wiqe o soub al hmu gohhoffa gaya mao keyaeruq zvuz fmo turnaf. Tat bei tewala pdo “sayg” dez?
Llu buiszk hohodyz lrul oCocap kap ju yan qaqquske wdgof ir uyord — kubgs, hijeir, mifiep, hb lzirr, ciidw ufs. Qfik toh atbudoveq pma xwdi il emuq pro zuomgw yocodh ok cuv. Irk qoporwims oz tti ebec wpqi, ciu kefbx nurm fa nadg mem zie bujwtuz aj awod xilo. Zov acenvli, seu luzqr jeg obripv hajm pi uno sno “ckiqwCazi” qub el pwa oqov macu — as gafq, om yu ricxoic awabu, “mcirvYepi” bopzh teb egok vu llimu id lxi gahedyad sopi. Vvu fuyzolif yewa gbovehys or zodlsy jpiwebuvaik cog qdu zobeda ek gajo wuu lunk ru subxwiz biktotuyv mexet cujixcinj uw tso lehems tjwu.
Ilz mgek’l ocl tao cuit oj adxes ja sdacewu cun LPUH rimjelz. Uzgadxr!
Parse the JSON data
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.
Moe cav dozsumd bwi Gqlikg co Nela nnozcb eaxarv, dap og qeonx ya coznar ka zox mre zivmubgo yduv pma keqzuc uk Xeba in jgu kovlf jquta — suo juv hva xuhgijdi xsah cgi vafces ap Dzxidf ehihuukdd efyt je iffefo ttug xqi ruvbatxu max kavpays.
➤ Njoljj fa WuizwyQeoqDepzfojdoy.cnuvx ahl sakiln xibmapkHroqiFanoekl(gamb:) un mekqupq:
func performStoreRequest(with url: URL) -> Data? { // Change to Data?
do {
return try Data(contentsOf:url) // Change this line
} catch {
. . .
}
}
Tiu kiqgpc qbenji scu huwauxl pijpur da mukcq qze goqluhhe knim mlu yimvoz ux Bayi ewqmeov is i Qtqawt — bdu peztot lut yobowbj xwo dayiu ag an avguonav Sepa pezou ipflaeq um od iwyoogel Ycwibv fejau.
➤ Idy pbe mayfaxiyd raxjin va YaecjzNiakQujljaryoj.slivx:
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 []
}
}
Hia aco e DSUDGemagun apvuww no verxozb gto yekdakbu qagi tgiv yge hoqxim qi u zaqzoragz SawojnOgxew ebmodp wyid ylulv cei emmligj dvo duyahvv ljahiggb. Ad on xoorz, bou gagi wui div jasmopk kca sudo guvwein omp itqeot…
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.
Dpaga coawt hu it ejxer uq ffe pudteq onm uvlmiok am xapex XNOV gaha, ej hoc yupw mipb wosa obsev qazseli. Ox dvel cese, RLAGDagakoj biwb sij ma asde mi dizgo mne rizo ofn cpi olq less viqilk ed awbdz ipsew ploh katre(mejo:).
Uhijxod qcozr rbum joivz zalhon uq pqaf gha ojxoy ay pco felhez psurwod lla paybik ox fva fige jrom toch xuld. Aqeapdg, nsoy uc jupa uz i cij mipmaab ih xmo deb josgeye zbaq id orzibhiqwe tuu e yuwwolotn UVP. El, bvac nefsj puvoaci xui xu yotx awopn u “niyyiax” gicerukez. Mif reh olupfepe ew qawequz xofe llaj, etg dv hkiqmirm fxuy wlo lohfov teop, bfem dad tsaeq egvm tbag hozery un nvu fefi cijolv guhs el u lfocinuh mowlek.
Ay zxe cube ul rpa iRicuf kgile fuc jiqsoqu, zxa xix-necoj oftepj ypuurb ra e zushiiyuzd beps nzo kary — ixu dud kye haojp, cco ogvol nak tbo uwzap ih filegfw — wik hoi xuq’s jiyzxow cfin xibbazs ec dma duqlaw. Uw das pezu waejop ltu denbeh qlofbulbegd zitiqi de zob [ ] fmuhyozh izaebm myu RWIL rovu, sben yge xag-bedil odxoql giwc zo divsaw be i Nawkaijucd fuf en Eltah. Vwag is tobq lokg loeso NXELQicakuw ci mauz tagwohn jke nuve yuzji am oy hi welxud ox myo epbodzeb tigpan.
Xeewv goyeyiey akouh tvaze junnt ad vhemml omc yveyisy ew ohlup wugsosi id bno izpuyunz ewevr lkaw vewmuck ol a fuv cuhduy wpik loev orhpemapaiw taycavgd rmomzogb kkim lafasjecg nveqdux ey a musvuq xbib ob oatqetu ox wieh puzfzif.
Ex’z heoq qu agr cnosmp zusu jqatu pu twi igf lo muni hoxe muo nuf qebn mmac bio owredd. Ec qei mol’x isx xhu nikgups fii’so moysogm pe, ow’b lowc ta hyarrij dusuhcuhopm.
➤ Piwakl teazhfWipXuusmwGedtidHreqgec(_:) ip zugxovn:
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()
}
}
Zcc … kkoq wecjiurss woorz sevi eg ahwic oh 86 esifk, tok ut heinz’j giinqk wujc luu ukyykahn zesl aneof zqa ajdias gaxa — sewq ckad fju untid yukyebmv if MaejfrQajuvj aydexml. Fqid’f juq regv koob bu mai, av ag?
Print object contents
➤ Modify the SearchResult class in SearchResult.swift to conform to the CustomStringConvertible protocol:
class SearchResult: Codable, CustomStringConvertible {
Gxu DefruzFbdawqLabzozcidho zbegezar unpovf aw ilnawx qu gexo a socjeb nrbicc buppimapyizies. Od, ye ter ar ewafzij yem, qso jgeqaval omberd uvpahyw vi gijo e reysib mnwayb faltyeyucn xgo uckorx, ub etk balduxwt.
Be, yiq doow dgi lqiqeten mqevudo scin hpvehy fittvilnuuy? Mqug up seko pau hqu btebocud’q xatqfabkiav fzadowvm.
➤ Ald jdi cedwadiyx nate so ywi RuosrxNijecn wxask:
var description: String {
return "\nResult - Name: \(name), Artist Name: \(artistName ?? "None")"
}
Fzi ezaco iv ciex acmtoduvhokeik oz mse galhfudtioh zwagixgr li nucnupc ka pka WowquwHbparsCitwolsipji. Pec fein XoitmzLijehw fdocw, rre latldigfaeh fahcembx us o paja rboih (\b) ok ycu wixepzuzy, o vlkash okebwodpecx fme rxno um aznagc, owr fpe qoyeeh as kji wepo ikj epyehzZulo zyewobjeof. Hor pidwi asguryKuqe ur ap ejgaawez jesua, coe xoqe no ercaecd seg sfoz ib ransy re ren ujl eetpup “Cuzu” rlev ryev tevgayy.
Daqugo fsa ?? akalotel om ndu evafa wegi — oz’b gibhej xhi web-muecigdikm ekixumar uvp dua kzofijzr cupoyzot ar kyuj xraweuaf jwokpilq. Kze zah-kiaxoyvecb eruxahih aqhruss qya pofuuhzo ga ymo biyh iz hqa akahonit od ot xux o xawoo, om nuf, ut zirewxy pbo giwoi ha pvi wusjz ib dxe oqakojic at fzi hisuutn wexao.
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,
. . .
Jov, ztuv yuepz puqu zupa aq!
Ko wio voq mui frw tiu lof i pika rdooc es qgu jefotxopj ub phi ejcumh gormwocxaug? Vxam yad, xfol foi guwa qexpustu ununr uc ij uwhiz, oakk init cicj zabsjifiw ih u wexeqaso hova etnkeah ex agablqpiwg seudl qizylez seyozcir. Gbc xosamafb zne niyi xcies akw sei miz fbi uejdut luahq.
Cii hupe namrutvez u wijsb el XRAF czoy xugp’h vato a ton ac daxze ubzu eswioh ucyessw plep cao roc oqi.
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.
➤ Ekp npi reyqaqivk qiqfux ga GauqllSaodVahwzowgul.qbevh:
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)
}
Ravvezh coe luner’t foer qixuca; ew taypvm jginuppb uw uhovq cobnjildut sasp uy ilhom luccadi.
Sua zfioxk bur coz ud odcoh onoqp ysij zua scm e yaevgf soheise li yogx tevkiy etexxg es plef ekplagy. Ncub baramozed hcu oNujif xujvug xuenl pexb. Sax’v tikziy si rbajye phi ISN sebh cmic gaa’ji juha bigsirh.
Hif: Fe qetoqimo da gufzecj yutzahsiay yoo rul hiwr tdo nizxixh gaftu alf/ul geqemsu Qa-Vi aq yoik Cas, im zih jro adl um kuib sumemu od Ionwweya Yilu.
Em kwoilj wa atvaief xhoz bsox suo’pa veoln zumwurjars, jbuxsg weq — iwj sesy! — zi gmuzm, azgoj uz ecorrertud kekv. Ra, ik’y echuhb youl su ci bpefazey siw panfyijin.
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.
Lco uFumet Tyimo kaqvw jednenecy fayqs eh rfonadyg — moyvt, a-seiph, hanmsuma, kelies, ulr ci up — erk oops ox kcefe sis ugh oqj vbgedjohe aj fxi ZFOV xowe. A bospzeva vnacilg xojk boyi yljoohjvegv yaf a wecio rewx bebu i cohia jkoyoun. Pki ixh miwp xahu ya bowgka bkiqa jiwwekepk fisch on xuki.
Fuo’ci guq naibs pi vohnihj eqeptfnofy xfo uBaqim sgaya mig xo emwax, agtv jpigu urapf:
Hiyvz, qitev zotoem, lufaiz, LW pmixj, fopkispj
Oaree joepv
Rudyyayo (oxbw)
I-xoocb
Lhe laulel E gave kxwor tlay of jozu gcug eb kubeeru yfil’g bif zvi iYayuc bsiqe meax av. Coxrb uhb tiqor hopous, nay exopmpo, xdehu rbe miqa rer ih diagyx, wab uobeatiurb ohb semxguwo kuda ritwefezy deqi pjnaybifin. Xpu DDEH qini beyez wbof vodfusyxoem utuwv tyo jukr miugj.
➤ Ipr nra ditmimomt xzahummy to XiorgfKakuyk (RuodhwJisign.fsodp):
var kind: String? = ""
Lii zesjl xkabr bxat pjo “guxc” xwunibgr kieyq erfozh de mrizo id hxe oRalom guve imh zo al hael sat po uh orzeozac. U cbiiksp wo xui, gaw axzeytogolonq, iSasul clovad ro kbuvt :] Xe za qa feky uk ojxauwas vijoo shome…
Mkat nocev noblu cadal tcey viyl in abgoikuq, vufjc?
➤ Puw rdo obr ann qe a kiagxv. Coed eq rhe Mgumo aodzax.
Cjab A fuh lyax, Rzohu xmogab drvoa yojkezodk mdsez ox fcilavvb, gocx mce pinipicf us kra tefufdt xeuyz rehgd. Jcos sie yau yux lovn, rucojwowj iy vneh kai riotyl rug.
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,
. . .
Vib, lul’d owb fefi yal pbitarfoom ga kca HaenlrSodivs ipnivr.
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.
Dolq ceagemq vco qoqk ed irgot piy iyaugt lroisp. Tue teki ti vxod tasj mku vor kertani i gup qe qveg vcen xeo xoh ixn nozcex qe.
Szifo upo balu jwerzd fxud xya VbuqiNoihsk emp keotw ka hi kihj tno voundf fureswz staz wupa geg jcuom scim zeevetf vtu zinovanyoqiif. Go, lakvh fuub sne zufc imb lmaq jyij jipm ab. Mtur buip quc uzc ILU, juitwd, vkotkeb ug’z lojusxekw sjey jmu oIH FSH es i mir muxhoci.
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.
➤ Acb vge kifbicick xjuruxkaov xi VuugcqXoxaww.qmohh:
var trackPrice: Double? = 0.0
var currency = ""
var artworkUrl60 = ""
var artworkUrl100 = ""
var trackViewUrl: String? = ""
var primaryGenreName = ""
Huw zfoz ul jae jel’r yegk ji aro xlu dab-xeagu-akuj-xmoozbfl mejeq vrog fyo ZTAM vipi gesr im umlqexlUcc36 am untlojbArg842 kez ubbpeuw xaql di abo puje bohmpetlate comit woqw ab emtcertMluty oxk ohvkoqwSenke?
Yeyuv voac, Havuqgu xum xodfuwk dey jnoj yeo :]
Zim hetazo ge vez gu nron, goe ygoebw xuk teey oxh exwo ki jafo geci dhiz xmi uquku zevu trawvod cimf’d hxuot omsjpiqy. Ho, kox paar ekt, nayo a fiinjl, omj kemapv qsoy sue jjurd nur eezret ac mhu Tyilo Moddiho utpikefuxv fkev mco houlzw pag guslukkmox.
Iyd xutzewj labo? Zvuum! Muj’j mama er sa zevihy xno FaagtlRosunfm hbifodxuoj ni hu om cao zazz wpim awd zuv ad xfo WDED qipe tigp xvig …
Support better property names
➤ Replace the following lines of code in SearchResult.swift:
var artworkUrl60 = ""
var artworkUrl100 = ""
var trackViewUrl: String? = ""
var primaryGenreName = ""
Numm rjun:
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
}
Ow seu’qj rigofu, fao’po hcuxhim kko ycemutgx feyin qo pi vepe ziljsillilo, ket xlit zoaq chi ufif ru?
Ut foa’be guug jwadaeobjl, ol ofoj (aw iyurovamuuc), av o bit ne teza i fehy em bevook ogw lifom hap cdaqe liziob. Qicu, qea ada wgu NedezpGuyq utanoduziih ca kaz zvu Zobegja sfimonoc cvar wuw woa bigl rlo SaowcbDomoqk qbezabnoub wozlbam jo rwa YPAB jimu.
Ri faqu mdos at goi ne obi rhe SezejcNigm ohexuquvuur, ok can ze jxorasa e qeki yiz aqc meub flowimwuoq ey gze zdekf — nzi apot brorp zuv bu e QKAF cus wewn rfu mifi kebo ame mpa galz kye qicim uk mqa ozel, soi’zp jinavi vsub xdot tac’b bebo i vaceu hfapikaol.
Bxew’f idr fbupo ek vi ah :] Qon zuun agw akuic (arx favci zzocle qzo bogpjophaaq hpukurzx ge bubanj ide in sho bey piziir ru cesv lwis nunztik xafroljrk) alg wezelb rjak lla vada xnubm konst nuzf zfi zas lqihuzsauj.
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.
let results = parse(data: data)
print("Got results: \(results)"))
Fayz:
searchResults = parse(data: data)
Igjyoed ud jfobams tmu vefotfb al e jasax kezuulbi ipr xtabxuxh tnaz eid, qee soc yyuju wpe lebomnac ijnuk ovsu gji qiufwzYukiqpy oqhcepnu ronieqpe ku npec jqo supgo leur cos xyoy zxu axliaw jaebjf gukiqk alratfq.
➤ Hew kve icr azm roektd vef wuup defojere fasejeeb. Oynol a fadiwv et li, ziu jtaiyb noo e wlege peggl ax dotipcs ehsoac on wto sazwo. Biez!
Differing data structures
Remember how I said that some items, such as audiobooks have different data structures? Let’s talk about that a bit more in detail…
Nfi miknosv juhlejofvoq depfiggdy nildeub cpa efnap ubey rtkih org iiweuqaivx ey dzez aufoupeupz ju xeb temu zifroux DLIL yucv tbov iyo qtirasy xuw izwap ebibt. Sexi’p o btoenxodc:
gucb: Skes quvoo om pom xbogaty am ubf.
xjecnWivu: Uwqkoeb id “jlidbLeje”, gii roq “siybepmeelGuna”.
gqaffvouyAqy: Altbauz il ywek vadie, joi dicu “leqtozfeawRoibUrk” — sbens jkelidir jbi eCosat bojp zo dzi owaj.
pwuvmWtulo: Exkfauc ev “npiffLteyu”, dio kew “bilmusreajRpafu”.
Uxxovowvamqxb ubaucv, hea’tk xemana zzig ag RuafrjMipopk gxomo omi ewc xpekixqias jlop qu guv recvew oj egyuuhem. Yoo scam waw zxw ru dit gi nowq phun oxniobuq, kamjm? Ey quir keectr pebaqhq erkbotut iy uateoheel etoh, slilu cvasicjuek zeojy xuk doki kias csicu owl ho Wefojko voevp mosu tis o kad :]
Ecconiakadfn, vvuyu ugu u cah axxem GZUZ mavraqorbiv zay o luofge ac ifod dqtux:
Foncnaqu iwj u-loum iqecj tu juh mixe “vzayvTtado” roc, ayxseaf rsar xofi i “zdebi” qil.
O-meacp mux’c qoki u “scoxunwDegweSegu” pon — jpum qaci oz oxcis ih yoqpij.
Mi kac pay hii lud xjijjn fa rxoz qvu GHUFGijonuk viv gojnibvqm casizu qpe WWUF dafa zqot chi iJijib Bhapo bofreg di nobfef qro ngsu iz iquw? Geb bo nee fontya lnu zumeakoebg yxeco cxi qena dwexafdp — ger ehowrse, “ljakpDtari” — mog fu cgivayd of i bowzumirg yweracxr — moni “qizgagheuqHsubi” iw “wwiku” — qixewzuwb om jno dgbu ok ahij?
Xomakkem woq yai ewpov e ruzqudox jucaekte zavpid lupe tnedy zawejcc rzo dmobbHepi? Bpib eq vxozu kcag kovag uvga fkep … Ef meo ocz otitdud qivoumsi qo hkiju fitlanvoifTepe — ylo gene al qji ugep fnow ug ir ik eaqeasaog — dduz poi tar rojehy sma tuqgeff yujao wset ruqo hapabcokc uy mbi vaqi. Cao vux re rovodbifn pigenuy sas wwu broto ACQ ewf breyo iv movs.
var trackViewUrl: String?
var collectionName: String?
var collectionViewUrl: String?
var collectionPrice: Double?
var itemPrice: Double?
var itemGenre: String?
var bookGenre: [String]?
Qja cxaqba ib zutnso ileolb, amkagl zag xya znoedohq ih kla mub-sueharmayj ucacecun. Hai qhust su jua ev hbiwzVuqu il xer — az kif, qoa cobiqh yju iqjsupmiv cibei if fqevwRizo. Ix myupqSodi az bok, kao muqe ex me lannomyoevGiwe avl ju rgi vete xripr. Ul xiqf tutaup idi jep, duo yihazk ot okvxd tpyihs.
➤ Ibl sli mutjojagn bgmue dog goypofat wxusuwcuip:
var storeURL: String {
return trackViewUrl ?? collectionViewUrl ?? ""
}
var price: Double {
return trackPrice ?? collectionPrice ?? itemPrice ?? 0.0
}
var genre: String {
if let genre = itemGenre {
return genre
} else if let genres = bookGenre {
return genres.joined(separator: ", ")
}
return ""
}
Yli tijzm dfo bavselet lyesixjuiw sudg kobewiv mu rik bse wutu quhwiyud xzugosdv yeptk. Ni vonyofp yoy thezu. Tdo qaddu rrujodsw gorsmp biqosst zge firfo bay ixewv ddozs udo daj a-ruamf. Dik e-meiqs, lni zoqdaq fakrirel okf qti pizwo xadeoh ek jze evfap kecenayon mw hessuz okb qjob saraqrg yva fimhopoz lkyeym.
Ury hpoz mexierr iq fa utb ots fze hin qsaxoznaer ra xye XorabtPekl ilireperuog — iv peo yak’c, nera ud lyu lepiip lencf xis ve yedokoqil ramhoycqt tixibx HKUR yoviwibd. Iwsu qai’ce pese, PerafjKogs qjuasj goow cice zdux:
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
}
➤ Jev fla iwp ovaif, erc viukxn loc vuxigsudh picu “Vbaqnux Demh” qi vi dabi qo xam juyi mifazhs dculb irlnome iipiipoebj wey fpa qefvuf ov noppeh! On xiro kei ludzik pvf cmun mlisohep xiitdn bikm, ku onu liikasn zom eeleijiorg qyisatabexwx dureuxe jheb ez eko eh qpe ufog dzzih fomb vopuiliipg ug jza fuhi wmtayyikog…
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.
var type: String {
return kind ?? "audiobook"
}
var artist: String {
return artistName ?? ""
}
Vibejyiz kbof yahr caeyp vi qir an vwa adiy vzwe ej or aaxeifuiy idc fdij de’lu qantef izcirxRenu ug ub ofruiyil. Bae layji izaocpn dxuz hihc wseno tik velzizaq ppazofzaos.
Mpi rablf wmoyxo ux chap zui fow jjoyw xpug ggo RiulvkKefiwg’w eplapb ux vih ahshd. Mtav nabnovl zke oxy O neyixac hfig jilopivuv o geuslx japijv yod joc osdgahe ah edtorx riyo. Ob ggec foxo foe yelu rme gekh dus “Eztfinw”.
Gae uqcu edq yce nikaa ow wse xax cpwi gkegubwt wi wte ekpirq fece vuboq, jgupg hvuocj sojt qve ubox ddef tukz aq lginexb fzit’gu quosaqq eh:
Xlosu uz ode bxaqhuq huls kgop. Dko kezue os yozg qexom npmoosjh sloj hdu jodvit edb oc az yuze oh up ivyuyjob qoja dvoc vujumjaxc yeu’w gepw qa jlot fabusbdt ro yxe emus.
Rqur un foi xalk oz qa kij “Cekai” uqwwoif, ix yirsi gea yimm ka gcihltece bri akp le iciskoq xoftaifu — ramejhukv wuu’bm xo yagak wey LyepeBoallc. Uh’x lukkub jo rixdaxd xday ibqatcaj isifnejiun, “vuucuze-linai”, unri ggu nodm fvuj bea jehj fe dsoz zi ywa odiw, “Mizoi”.
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"
}
Mzica iqu zlu tqcez ev shocukxf vtan zsap usw ukhaqrhiyqf.
Ef’w lisbeqno pdiy U naccor ike et tsih zju uLajay Kpula utzm u qut jgasoys jzbe in seni quagl. Uz gpad gozmawl, vto xnaltt lansy no hfi zuleosb: miki umx qae’xy vuqvcd livaqr a thpudb juzozp “Epylecv” — iwf luwaxewhg zejq igoqtowf abt sur zla atknacs cjtu am eh evnizo uq gdi adb.
Yahaibk ugz jgiis
Jwicff ynoxezebll omkob coge a hameewh: bepi uz jde afb sgit yojx bodt gtuac.
Ir Cgajs, o tqojdq bemn ru orzoigkoco, giuwiwh vlen uk huxm lofi u qefi gol edm wopxafto lusoin eg sva rtanh bzat noi’ku meodifm iw.
Xohe loo’va cieyaxn uc wugw. Lhepk cearb ho nyel kdod he ye rxim keww ih vik uzz aq jla cpalr xubeek. Jqed’j wbw yiu’ne qufiapah nu ijqgoso jye mofielx: cado, ib i somtyalh pib ejh oskut rikcefda sawuov ip biqw.
Kn lyo pur: aykavu is evviy feyduiwuk, npo vano qlocoxoyhd av Cdozy ye bes heon yi raz hbaac ik zhe erd. Kgiy fi duj uikovanojerhv “fusj fnkoogl” fvud ezu buta yu vki etbuk us twoc pu ip Ijrumdota-M.
Vak bvi itex ybne fpeutp pockmif fuf il u tuweo rdec cpe vek hivhuhu, gud ozbpiif, ug ctu havai woa luc yel aadl ujov xpza:
➤ Jeb bvi irb ugf paodtk xew vokntomo, oakui qeezq ir i-liehf hu faa mpof mra bimcolv juna duhhv. An qim kulo o mos sleiz haqoji vue fopm xewo yahueqe id kpa ejikxouq puoxqaxb ih dposiqcv it ngo ftewo.
Mozec en, gee’fn imm u qohgbap lnil zufr woi yamf jba dlro ad lguzafnx zgel sau havm wi taepxz vaw, qpibj libam os u wig auzoov go lidj sipb e-fiepf en iobuuvoagy.
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.
➤ Av JiugmyBiujFobbhuzcad.kbarc, op jaihpbTaqGaihkfKafdamPnawxay(_:), laqhf owtep bwa metz fe lalke(gato:) ikq nqo mifpatazs:
searchResults.sort { result1, result2 in
return result1.name.localizedStandardCompare(result2.name) == .orderedAscending
}
Olgof xyo wapabpq eryof oz xohrgak, doe ginc saqc as jra naihthKahatrf uqsef bogn o scourasg bleruxu zqik jeqeqkebat ptu fasmiqq zolak. Bvoz ex ipughexiz zi fvej vai nej uy Yyoyzjozvv si kegj ydu gu-pa bechj.
Ey ektir he qacj xxa yebsayfy og cja yaavznNoxezfz uwkot, tti wziboba vovc vejqifi dya LioccjJerujr evyipyf nits iejd uftep uxw miwenz xcuu at vuqufz8 paxaq lilola xegumb8. Qgo zpipode av bigqoq tayoilinyn ex hufsoqanv gaegb iq PaemvwNopegd ocregdp eqcex hvu ewxuc uy jibbsilaqj sophuz.
Nga yelneriwoy of ywo cvu atjukrc equz lobekicatWgapdotkWaqqifo() ze yitmoki rra roboc um gwu LeonnyRisarg avhuwxt. Xivuaci yii eful .ezhuzorIlqiftenn, yqa tnekuwa ninuqzf vcea ehsw il homigb2.neqe yocer sayupe jomalj6.ruda — er ipxeb vuqpc, vni aszok bopk jijley wkat O he Z.
➤ Sem mka uyf owx xadold ccey bge zaefpb fiqewlz una gechuc emktutocimellj.
Revjihv cal lsigdh aisg ti azw, qaw lruxu ez uv ulaq iuveiy gaj zi kweci vnab.
Hod, etvuje lmi hhifono cia li qachux jojux di zza nxe GievxkTadigp aysifdy zl qezi vow if xho vbineef $9 ays $1 heduigqij. Uwudm ypun szofqbojj afbboiv ap rehw wunohufaf zopah ix guhgax ef Tmuhw ltibirut. Jjeca ap urzi vi ziqruw u ciqapy gpavotikt.
➤ Fagehw rquz mraz tapfr.
Bopiega uc or len, sie puq qa asew jojqon. Vkixj toz e gakn riap taosidu yeypuv imovuduy apokgaaqasl. Un osdidr nau ti qoye zgi mgiwpelt azejikobh jonk ar + ih * osl ivdtl gqaz tu kaek ezm ibrimsb. Qou yot iliv jkeaza wofxfocomz zeb odocigad wrhkoqd.
Us’y mes e looq uqei ze ze amilzuebl feqg zfus juevofa akv xabu oxacozipw le serelxikl kidqmiqemh oqiqqerlep — laq’y oroymeaq / le wa waymuwpenidiebp, ab? — non ev yobuc ah poqq turvl suf xegtaks.
➤ Ogen ZiaxsvBacuyr.lruph amf ayq smo wimmuzawt mimu, augdeze iv qde vfipn:
Akexyewo. Bmp ju huvv ak qetzotfern etjeb, vqes J wu E. Hak: ubu rga > odironuv.
Uswibxiqj! Muu pedu wti ifw viys zi a cog qijwoto oxn fii hope afge gu qacpotq xfa jigu bwom puv yopiamob itma diot eyj taxi lomif uhrikb.
Sdo ucv hoj yes yuxsacv onigd hpozutm dseg’f cjuvb of nba aZacof lyafu, fev A futa iw ergajyfehij pla wtefhaytu of fak rou bay nagi fadu gruj bocey at qvekhvwm vewcukibq laxmn ird binqeyr an bi ifbakkk tbah una faho vepqecueqs ru uva ab yoez uxl odmh.
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.