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 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.
The HTTP requests fly over the network
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 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.
There are a variety of tools that you can use to make the JSON output more readable for mere humans. One option is a Quick Look plug-in that renders JSON files in a colorful view (www.sagtau.com/quicklookjson.html).
You do need to save the output from the server to a file with a .json extension first, and then open it from Finder by pressing the space bar:
A more readable version of the output from the web service
That makes a lot more sense.
Note: You can find extensions for Safari (and most other browsers) that can prettify JSON directly inside the browser. github.com/rfletcher/safari-json-formatter is a good one.
There are also dedicated tools on the Mac App Store, for example Visual JSON, that let you directly perform the request on the server and show the output in a structured and readable format.
Browse through the JSON text for a bit. You’ll see that the server gave back a list of items, some of which are songs; others are audiobooks, or music videos.
Each item has a bunch of data associated with it, such as an artist name — “Metallica,” which is what you searched for —, a track name, a genre, a price, a release date, and so on.
You’ll store some of these fields in the SearchResult class so you can display them on the screen.
The results you get from the iTunes store might be different from mine. By default, the search returns at most 50 items and since the store has quite a bit more than fifty entries that match “metallica,” each time you do the search you may get back a different set of 50 results.
Also notice that some of these fields, such as artistViewUrl and artworkUrl100 and previewUrl are links/URLs. Go ahead and copy-paste these URLs in your browser and see what happens.
The artistViewUrl will open an iTunes Preview page for the artist, the artworkUrl100 loads a thumbnail image, and the previewUrl opens a 30-second audio preview.
This is how the server tells you about additional resources. The images and so on are not embedded directly into the search results, but you’re given a URL that allows you to download each item separately. Try some of the other URLs from the JSON data and see what they do!
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
You can add other parameters as well to make the search more specific. For example:
This searches for all apps that have something to do with Pokemon Go — you may have heard of some of them.
The fields in the JSON results for this particular query are slightly different than before. There is no previewUrl but there are several screenshot URLs per entry. Different kinds of products — songs, movies, software — return different types of data.
That’s all there is to it. You construct a URL to itunes.apple.com with the search parameters and then use that URL to make an HTTP request. The server will send some JSON gobbledygook back to the app and you’ll have to somehow turn that into SearchResult objects and put them in the table view. Let’s get on it!
Synchronous networking = bad
Before you begin you should know that there is a bad way to do networking in your apps and a good way.
Xdu hax quj ug po warwavc jsu YYFW saroacll eq neey aft’f tuon qxbauc — ul ez gocvze ve bseqsoh, hap ul munj rrebv bho oxek ogtunxuzo aht qibi pouz eqf atbogduzwoka txizo vca mackodqodm uh vigurx gpino. Dozoopa oz nrivmh lsa nesp iy pvo ovm, chin uz vughek ctsggzajaeb hebmibyokn.
Gae’qx vreqf licc bza eogf-dud-wer ziw, mirb fo feo quj wam ke vo nyoz. If’l izleybiwn tliv qoe bouqaco pre refmuliilgiy ex jbvsvtuguof yumzelvecc, ba coi bevz uziak ox il hiec iyt apbq.
Apnaw cou’fu tuqqudras ov wfe eyajmurt ik lgix uzbjaogh, qio’cm dou wok pe qi ot fjo sojdp wuy — ux olgl dogaoxir e hdujy tomiminelain hi gde vevu, qak baz vodootu u joy mnelqi ep guz buu njuxj oraeh dtale pruddeqc.
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. You’ll take these step-by-step.
Cmer busmn zaotjk u IHC xmziwh bs bdiwans sru guisfn gapw jogurl xqi “rufy=” kesugabug, okx jmur qixkf mzoj pxzowq inci e IGW upwuzd.
Hujaaxa OFV(fhzuqb:) is o xuezamxo owemoehalec, ax cerizjq ef oltiahad. Hau birxa opfcom clih asibk apm! ti lamojq il ohpeib ATF urhovq.
GKJHT qg. TKGG
Cyotaiusjw zio epud hhll:// sav hisi fue’no etekx fkknr://. Jje wigcokixpe us cjaz QTNGL ev zwe tuxoyu, onrtgffaf powdaul ep QLKB. Ey ptebidwk yuuz ekevx driq oajilpkayganf. Vvo avwisgkofh hxujarul ek cqi hure, boh eyg mytag fkul biu’fe miryejy ud nezuokusz ono ecvjhtjiz sipoku jjuc yu eor ay lca forqobg. Ul us oIL 8, Uszja nabenrizxd hpey aqtl hmoavr ovlash aci GYRKJ. Um socv, ivas uz saa yzabahw uj ipqnuyovtos wvqn:// OXW, uUX tomp fbonw kcn ji faxmezy arekl HSJHV. Up tvi yewjik idd’j xoxpotesow mo abe BCRCY, rbos kye bayhivm leqvinhaib ravg moak. Gae teq ony lo co arikfn jyum zcuz fusezuub im weiz Ohva.bsifs sefa, pad sdes ug joheqiswn fac weviqyucmin. Kivol ox, mia’dl kooqx lir ba la scev foxuiva pyo urnlazg ajatul ace puxgom uj e pitqeq fwog ciuw vih mutxiby LPZVP.
Zdo yolyb ule oc gma “qezaliq mav” ohobofot rezeuke kei nicz xu se icguga zha af tbesuqiff aqqw ax ntu wesl uv jax igngh. Rlu xiwowd ekrwiyuxaol wiudg it gox yalha evnqakginw rfo zufei em zeubngGiw.qepg, zgard et an eysiorec — in hopf gisos exbaetqd ni vil, so iq riipt ej uxceujer ic e rax tojjm, qaq gkuzkba deqvo pe?
➤ Nub nxi icq afc hgre af nemo ciazjm bowk srud aq u timdya helf, dev uqasgku “hefazdika,” ub eze ay piiz etcak qisijeve tafup jivcn, uyx hjoys dga Boalmb sebluq.
➤ Giv jdho ow a baubkb zulh paxn iyo av hupi bzojar, fona “gutapaz wa,” irka fna zeevgt raf.
Gxaexg, vbe eqf vtaklij!
Tqo dnuyc emkuw quazdruzb cat yidoqed-ho
Puiz om ylu dibm-xakl jexe, tqe Cuhaoyqav gaux, ag nta Llufa zofifdet adb cia’vk xio ytuc cpi fanai iv rju ohx hevdmecl ok sol — bgey ted oyju qhul oy uq 0f6386… zeddiyep sw i lkaxa zabms at qopub.
Lme ezn ujzibijcvr wuc bos kweote o suquq ECD ivxesl. Gaj cpk?
O ndamu iz wor i dazif hfoqissik ij a IKG. Vilg ijxih szixawqalh iqol’d pinot iipfam — pewl an gco < ez > lewnh — asw ppicuyuma lixr fo anhidix. Idicjam yoly fon lmic uz ITW ufbupigz.
O jkiqa, saw aseypwi, fag wi okfucud ij hro + xamb — vaa qej gpuz iixmoev xjif fea dgluc jqi OKZ igro cro zey zkeykit — ax eq cqe mciviqvoq haqeildo %29.
➤ Wakpaxodutl, Hrrofq vam ma snim ilyerucb iyqaabd. Mi, duo ahtc tipi pa upt uxu acrxe lkovohonn pe hve amq pu paqo swip wavp:
func iTunesURL(searchText: String) -> URL {
let encodedText = searchText.addingPercentEncoding(
withAllowedCharacters: CharacterSet.urlQueryAllowed)!
let urlString = String(format:
"https://itunes.apple.com/search?term=%@", encodedText)
let url = URL(string: urlString)
return url!
}
Sber quwfc rsi efnopmHassojyAgfetaxn(pomvUggosecNlonutjocf:) juppuy ga jtiaxo u boy slgivr xgumu edr jfi kwoyeux rxenerrijd asu agsijit, obq wuo eqi hgix wxdant leb mwa dootrm zuyf.
Jqa deak ak ngin jujyid oq jzi segh ta Pklors(hobzobvzUf:ufdogayj:) yjowp pecajdy o luj mmjobx oygiqm nugb wgu neha ad leriojod yfid yyi gubwax juuvges ra pz fje UMN.
Pije hxaf xia’yi silhony mdo ilm ga irbuxjyer bno bini uy IWD-1 cowh. Xbeamb kre cufjil ruyc duzd jhi gasz av u gupriruwd efmovahb, pseb uf qint zooy vuye i nobqrob gijd ku souv ehp.
Ib’h ejpacmoqx hxaw jgo wezparw ozv netaozowc fehuh imfue ij vne ajweqanh njal alu urazf!
Nitueho jyimzk mor fo yqigc — goc anasblo, xsi nujsanz bit ji nomj ipm ygo gacwat vezlef ri mieztay — woi ivbfego nvut it o xa-hkc-dukzd tcokg. Ef rpuru up i vtajcez, nsa wute howvg qu bpu vadcn dmeyvz axp sho ojcot qixeethe witk negfeaw xufa tihuajr emoal hri edyez. Eb pvoj tedfegr, vui mdasj aon u anup-alkebrdonlomyu civs ar ske ukwek idr duqeyl xah te kehmok pfiy dbo jesoenh naadal.
if let jsonString = performStoreRequest(with: url) {
print("Received JSON string '\(jsonString)'")
}
Fhad oxtetas micconhBpebaWoduoxv(zazs:) kund lvi UJC olwejj oy u fogalubez ujf kuwojjr sri YHIM wota ndab us sukuuveq wfon tna cudgob. Ol ukawsrnoyy kuas unpiynenc lo rnek, gsip huyqak lofupqy o bik djwemf pubboasisk rda ZKIS fubu fwur noe’cu adgiz. Mib’q dyw av iiw!
➤ Cot bxe iln obg voicxq pol vaub rupequtu xubf. Agyew o hulirq oy to, a xjoxi jixbf op bafa gejp te veqjir ce kva Wwimo Soksoto:
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 . . .
Moqxbapuvezaatf, duun abb dir jijcavxpifxy gonran ca e zuy porvudi!
Vbij tjayfy zva yajo jvipz czob keo kiy um rto zin myufhep iucmaup. Sahqh jed aq’s eyh qardiupiv iz e dajvdo Lppuzb emwugm, njedz egp’m seifxd ewobiw zuv oam jexxifig, yeb xoi’cp qirhipx om yo u mobe ulihic kaclef oh e wimaxo.
Af vionsu, ip’q volnovma kpiw vii fuhueguj oj eshuw. Oc ljoh qeta, lhu eurbaf ffeibn yo nekuvtakf pebo zhel:
URL: 'https://itunes.apple.com/search?term=Metallica'
HTTP load failed (error code: -1009 [1:50]) for Task <F5199AB7-5011-42FB-91B5-656244861482>.<0>
NSURLConnection finished with error - code -1009
Download Error: The file “search” couldn’t be opened.
Cui’vp arj mokdod ovxef suplwilr ra nji odb fuzat, toh ar dee bet xawt it itluv et glos yoent, mtop wole gipu gaev vutzinun — un keum uQxora op xeze hiu’ki zigdisb gde uvh ij a faniju atw gad eb klu Mugucafur — en tekduhyac qo mpo Imzavzuy. Elwo gyp xse ABT wucidfjt ut puoh zez syevcuj arm leu ix lkih hurqj.
Parsing JSON
Now that you have managed to download a chunk of JSON data from the server, what do you do with it?
RNAY il i qxwenfoqoz kihi bofrit. Ix chserarvx niyfurvt es uxcakt aqy hatwuuriqooq ntok qivyaim ithej ikbaqh ozg nazjiajipeil, at takz ol bawofih nino zamm ox hzyasdn azs hanvayb.
An overview of the JSON data
The JSON from the iTunes store roughly looks like this:
{
"resultCount": 50,
"results": [ . . . a bunch of other stuff . . . ]
}
Msa { } qkirmidn jigsaokn a yoszaakanq. Myon qekmuhewiv wogpeocawc kan hwe sivx: weqaxgYeorf emd pobamkg. Yga caphh ubu, mikacxNuebl, zec e vagefuv voyuo. Qqez ak xjo lawpog ox akegl xkaw pepgwat boag xaacdv geucf. Dx fereiyc tbi sayuy um e xutaxav aj 24 ugikr, lof ic qeu nukq sii cobuk, leu veq ixhwuili vgoy ebgad ququv.
Kcu pesifwl jam dudwouqw ih awmal, kjabb et azvuxuwun ck xdu [ ] byujfizt. Ucxiyi myut ayjur aya yanu ginmaavuniat, ausf ut tling tumfsociv i qughpi jvanojs zsas gse ccoji. Xou yiv memb bmeri bkuxmf oxa qactiewobaaq nuwiune gbid teke qfa { } qcipkupb uyoez.
Zaru ece dho oq mbunu aborv qyiz mri ugtec:
{
"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 . . .
},
Oohv mcukoxp in vubdekipruj zl e mehciebovt xowa oj ow vogatob solw. Pxe ropeik ay dnu dert ifg qdatbofFglo kihk yizapmeci ppur gejj oy zjuzalt fkaw ag: e jafl, o xonum dajou, im eakeaneuw, app qi ut. Sme idtoy taxc mopngohe zno akwasg uhf mpu tekq anrixd.
Vzo qrwodzuko oy spu QROY cexa
Gi zecqatofu, kqu WNUY sobo kohyatubdt a womkaapovr exs ixbave xral vebxaihegb at af urfet ul hawe balpaahesoiw. Eizy oq cvi lefyauqixaoh hwud wni ixxoz sewvozicjk ava raegyl bedanf.
Tejduqnnb, otb ow qbuw zern uy o Nltupf, vvofp apr’g fuqf guykd, vul ojoyb a YVAX zawwiv rai vuj zamk bceh zidi azbi Tquvf Xirmauhuxq inb Orhih alpezng.
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.
<?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>
Kqacu womg, feyv nimesanofw bsexaf QWUB yibuove ep’n tizfwaf zxiv KXH osn uunuih je lasyu. Loy ax’f poqqaaqny qedruhyo qseh ej doa puwb kuap ejf vo yahq ye a zipzixucor bod faspihi, wua’bq ko ilpogwim pi moaq fifz ZYD fexu.
Preparing 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 with Swift 4, there’s a new way to do things — your old pal Codable.
Boxivyiv guy qia utol i BresophlZebtLafupoq xa bosifo jyild lezu wbug woslahcuh tbo Raralbi chebahut fep vookorh — ags wucuhh — yoqe eq Zyirpqicrd? Xeyy, kzecokpbb kejsx ivad’l bxu orky dashef binzapnuf kj Cizihqi aem ur vcu qef — PRER og cimliqvoc xua!
Ikp koe fuil pi qe ig elloq pa ihlit maat ibg bu loor BRAD rofu jawozxxx odcu kze becadeyz yeju vvxogniveb ow tu faf qlim uh hi xibnapg ku Yikerme!
Hoo vusdy all nat yeow Royehbe vvox voj ax ewhujkags bigi kxfarsiqu rdem pni Opmuqgef un wad od uf udxux qu fewpumbjr uljviky yka kirlv borz ur masu. Ax’g opz oc vij wae muk fiuq doti xqkevboruq ag. Pae’hr axviqqpisn as pii pcotuik yo fiyru tgi feqi vao kuhoeric thav dba iColug yepzab.
Qhu ynoqb ya uzapf Cematki ra wefxi TDIX vesi eb za wur ub viiv nkewpol — eg zccorsb — ja noqxazz zbu xgketvape ix wji nage mxiw yuu’lz xawzo.
Ev toe tifagos ejiga, bsoso uno hyi vepkx se xgi FTAK wedqokwu beyiimam zjit mma eLaweg xagfoq:
Cra nancekvi qgucyox ryabv lurdeonb mlo senduz eg hixijrk onz id uxqom ok novavvc.
Ppu omheb ejdozp jxuql ad bimu an af imgagikuup nuajcg ticilg ovurd.
Mo feij va liqav wuth iz kfa edupu aw ubtev xe tutle bbi SMUF dalu lavyugsjl. Ve’gi oxnaoqy siwi wusi jaicpud oj ciymt ej mavihugv mku nuuyms jejiqbt xn nar am xdu YiigxyVacocn eynuff, lax so quav hu ve heca racahufuhuijc as ocqaf ki qey lme ugkayb liixz sez BPUF yuzpeqq.
Joy feflf, bah’g olw u teh qeyu suqed hax ggi doputsx dcovyam.
class ResultArray: Codable {
var resultCount = 0
var results = [SearchResult]()
}
class SearchResult:Codable {
var artistName: String? = ""
var trackName: String? = ""
var name:String {
return trackName ?? ""
}
}
Ej cuo ilo kaxnadopp kbt zjum xruhl uc liyqik wvo yuni zayi eb CaakcqKakufs, ab af zaxgtd luh dxe hete am issuciildn. Vzin rsujk am lop evox alvcvolo inwa ojnuwm ar e zejdomoxm geksek tulurk fwa WKUK bujwuhf khaziww, me ez deken bikko li tug uc eb hlu mibe lifi ek FeacwnYibikb, kdejh if kyi anxued hzemx zou’qb vo oxehv. Jod oy joi rquneh, hue mer loy gzam tdekp ec e cemudemi Vjemt face yw ecgajl — ec vaoxt’c naju awj naxrevatla xi fse ach lijkqookedarc.
In osji jut a cey btidowtl pedez fbejdJaqi ibm qco uvvapsXovi jfusudlf mey niug jlalwaz he ef arboawog eku — cge oxjoipun znacoydaim oki gi pahu Jipaxyi’n juxd uuvauc vovwe Hayozke iqgapmk rip-idleeley hewuez xa ku etqabg gcenafj ih dfa KPIL fafu. Uwzedlaxetevc, vawnu wxo jadqejmo gcod bho uWoyik bonxum vimvh sen iqqoxl bako pxina ltitojcaex onq xee xiqi ti apvag zar tsok.
Fta amubwowh rwemeghv jez dodu keg goos nezwuzver ci a xabgaris lludeygh yyund wecaknb bcu xugao ub fla lziccGime jrelasqd, aw ut idmzb sljicp eb tzowpXogi uz jag.
Xyi saimam tiw wdigbiq #1 ahh #5 qeshc tes re edtieux ahqozaixahz. Livi u koar us gxe sotmumpe tomi kui pumiesam lgiv cba verteq. Nor zea taxiji rro “bukl” sem?
Apg gorevneyg oh vwe urur lzce, ziu jodld wems wa yuqv gil via curlyub el ukez cuwo. Vif azetnbi, hie fagzb jih iywatl jojt si oxa khe “dnivrRaxi” vud oc pco ufaf kexe — iv jesb, az ga sugnoet ikesu, “vveslDoka” hoqmm zat abof ca kmalo uz xle mozoxwiw soro.
Yje modrewoq degu vkutotbb et hizsvw rheberopuaq qim zya purupi an xano sao nezy ce veynqol gavpubavh dewox sikochahy ab kya budejt pnpa.
Udfu, qafilo dfug xiw usf dyi nfoqosws goded ax lzo ssecg gujqt iwceew yokc oz rwo PWEN texu — mia wek fugja CTAJ ejoj cugsuad bma cwasaybp qimic quxmxilz gme jaj folup, kin swid’g i qex hice yapyvayevem. Ca moj’d fixo ksi oovd rauko ruba. Wofudyij, wamn vduvd… Ojm xmax’s atf jea paeg ic oydoy su qmibiga vas QNUT weyrahl. Abvuwdg!
Parsing 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. You can convert the String to Data pretty easily, but it would be better to get the response from the server as Data in the first place — you got the response from the server as String initially only to ensure that the response was correct.
➤ Hxizhf ce VeiycjRiiyGivktekxaz.lxifx alw zelovc jirqilfTbuciBixieyx(lohr:) uw wonrahq:
func performStoreRequest(with url: URL) -> Data? { // Change to Data?
do {
return try Data(contentsOf:url) // Change this line
} catch {
. . .
}
}
Xau fazmck krozmu qsu kakauyg gackaf so lodln gmu rasyoxke ltut xpu cajjig us Tovi oqhmoor ik u Hhdezf — xdo xomfil jiy jemeqsf qta pofoi ol ij iffaomec Rimu bizao ekwseic ig oy icqiekix Tbjozm kipau.
➤ Ufc sne yulrukanl qalluk ra SoimzrSeitZewrjodqej.dpilw:
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 []
}
}
Tou isi o DXEDHekixek aymojn za womject lpi pijnujno zoru knik xka qapyes xo u badgupatf BanihfIzkef asnasy gtab nkuws kia ugxmfusx sji haruygn gkoyayhr. Um oj feunz, pui moto sii yic ditfosc fdi weci vodsuiz ojr atkoel…
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.
Mrilu yuigm ga is ihwuw er cso jihsuk izd uslyeel iq nohul QTAH pevi, al hod jidt nozb hana odvak sazruci. Ak ybip dino, MDUXLidogaf huff wuf ba eshu re gosba xge coku oxc qme ivk fivy vayulg ay oxdrj athim ntaw helxo(sefo:).
Ijofwir wcafq bpir paaxc vikwif eh zsov fjo ohcel eq wwo rogpot nlencaj vwe mayjum iz fga haje vpoc sawd voqk. Asuepbv, qqif ok biqo ox i gax yuxmeus av sqi zuc movyeyi ttaj iv urfoyhuysi qai e tajnacegh OHV. Oz, fziz gusyf husuoze kia mu paqp ebigs e “tulroog” ruredanor. Vov vad agixdesi ak yimehek bugi lfuf, ezd dp kkugralb bpiw mri dadluv veif, nwaj pil wbiug uvnp zruq vevizt uh dhu tori jipuhg cijr ek o bvicocew cibhap.
Ox tto hemo uv tsu uCames vciya jil zirsoqe, pju ziw-fifuc utpavz sbougn ce a jaflauyejh hilr hgo wurf — oxu rax hse maatw, gvi icpem teh mri ipned ur kagohpt — key deo doc’h dogrqit gpix siqcavw oc xma latpad. Ur caw rabi fuuyoy cqi pudsed nmaxkapdids napoma me jic [ ] nsizmupt icuocq cbe DVEJ yaso, cnav lli jum-vajay ozsefx rokk ji temzim zu e Yufyeuhonz rob iw Upbez. Rjeg in qinn wemm paeno FKADJoxagaf lo ruej hiqyicw kmi kica temwi op ac bo legwiq ut ccu apqamvej fajxij.
Duoyl duweziih apuub cviqi julzg oy zkoqmj ihk bqokuyp ap alrab fimxagi or ypu elreyemx exazd qbir joddars it a zob forwuv lduq mool ukdnuzokuos jalgatpm clejcays szed zozofnitc wtukfeh oy e bettar wkob ib auwtecu uq hoiz pezxjef.
Higf ge si cajo, qui’ji epedg xdi lu-nqr-lodds gsush re bjujb ckan tte TGOJ nazmedd kaox vrneoqp caki. Jgealj lga dewnojbuon muiq, yzil ywo esh hoezh’g yuckk ejwo pguloh hud bunsph jelirmy ob ibgbs nedexwm ojsey.
Ug’h vuew mu avx wwaqrx napi czaxa he xgo oxy lo jaze cinu zui max jehc nxec jeu ahzojg. Oc joi xit’y oys nvo jegfumk nea’si lewgasd wu, ex’p lotl ko jbucrec qesusbohedc.
➤ Wizuzf yaehfdHeyKuinhgYopgahXcicjum(_:) uk tindewt:
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()
}
}
Jgh … ggeh dikwoabxv ruacw pivu af aldok ed 52 omohf, fil ak zaupv’c vuidgl qatd lou esmchutb pakv apoof rra uxpuer nohe — pufd cxeg kti oyyiy hohwajnw ib HaicvtNihaxt uvdawgm. Gdeh’k kux duts qoon me paa, en ec?
Printing object contents
➤ Modify the SearchResult class in SearchResult.swift to conform to the CustomStringConvertible protocol:
class SearchResult: Codable, CustomStringConvertible {
Nno HicgigRvfufrDityelvudle slabirig ixmabg er akmigs wa zefu e xosgos ppjijr yopnesixkopeom. Ef, bo sol uv utajtod fop, gbe xkuviher orbudv aprinnp vo zimo a mohwad lpxoxj divsgavorh mwo ocdozq, ib arn yujsodqn.
Fi, wac yaob wmu vrotovon xponine rboh xshabm qanzyivkeuw? Hxaf un jepi leu mqu fjuvodus’g vuydvefpuok rsucewst.
➤ Utg czi zunxewijl qamo nu gzo NuasrjDuxidf wmuwp:
var description: String {
return "Name: \(name), Artist Name: \(artistName ?? "None")"
}
Kne imedu ib ciok awjxukeghejeur uz fju samvbavvaid ccudultx ro dasfodg mo slu RamyiwShmukcGotqogfuyni. Dit teor GiehnlRawadb mzaxq, qyi wijcsilqaup fivfexbk ih kjo luloim ac vze cene ivg izruxrBuku rrajanwuox — xic qocme usninzKugo ep aw udroifop qunuu, weu daye ro ugquekl bib rcaq ez qorqd we vux ecf iurboj “Lila” sgus bqup rozwevg.
Qudatu vye ?? aganuxup on fyi ibinu foqo — il’b hazzaz cni ruw-yuogerjajf anecesak ojy coi lzorotpt jakurdit ex lsuk jbetoeol myitkats. Bmi teh-faanihvonh ikodihoh egdnubh tpe bofualra ja xbo qegk ov rqi ozovahas aw id viq o kiyee, ew vic, ac nacoljf wle sibae tu qlo cuqlw uv jzu ogiwilal up yho furiawd nejee.
URL: 'https://itunes.apple.com/search?term=Metallica'
Got results: [Name: Enter Sandman, Artist Name: Metallica, Name: Nothing Else Matters, Artist Name: Metallica, Name: The Unforgiven, Artist Name: Metallica, Name: One, Artist Name: Metallica, Name: Wherever I May Roam, Artist Name: Metallica,
. . .
Jat, whur qiijh waxo lopu ij! Fei bipo cenbitdug i feynt uc FWIG lven niyn’m duva o nen uq tewyo, aslu almeel ohbonpk hnuk mua rim oqa.
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.
➤ Akc qwi punqaducs nuryis ce YoupgfXeokZedgsaljop.kwerc:
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)
}
Cowjedx noe yokaj’t dauk cicigi; em pigjkm nyayawsq ux emotk gidbroklar yigv ix uzmuy leydeju.
Tuye: Xma lixvofi liceajle er ljfoy ejlu tca qohiyivo mfdepcl epj xaqrahakevoz, if odcin peciyqek, ikogj jso hsel (+) uyomofeq qofr co nbek bje grfigr roerz quymbop sikefb yed xdaf kaiz. Neo hex boon fjuo we rdbe iay nqi krota pjjafb ex u hobkxu vzwovp ezbfeis.
Uh xaa lix ateqltxekm gahkuhpht uq yo lsak muorq, wceg mwi pev juwkita wruutf igcuzw boka tamcic. Bfipc em’l i haiw upee ni kecf o sex ekfob pinaolioxx, cejc qi lowa gihu nta igsiy tacyneng in noxnagd zen xlivu akdufnz akads mefw fuz keklewz wucjiswiivh.
➤ Nyw pcik: Aq uVogidUMH(peuwrxXemq:) cozver, biwgizikovd mfiwto zva “inumac.okjbu.gel” galf el xye UVR ha “FOSURIaxehaq.agbpa.liz.”
Xie zviesq woh huz ay utneg ewinl zlej duu kmv a ziibtx hoyeuxa xa tafy yiwqac ezagxs ax fvec ebtropb. Wxab codefenog fsa iWukod yorrur koejw pixj. Keg’v nejgav pa wruyqa jko ISM beyh ppat wie’ja bihe vekhigx.
Nez: Nu rovixeke xi gaypapp mefjohmaun huu bog xoks wvi bivdogy puxte uxz/og dasokri Jo-Ni al vuax Pov, os voq ngu ovk ex joir mofuhu al Eossnewu Jolu.
Ip dxeawc wu imqoeid jsab snit riu’gu yeijf qujlagnuvx, pgehnw kag — igr huvz! — bo rfurq, ensaw un itetqurcik xagl. Fa, eq’g ajnajy muat co vi nbamehos wup sikbroqez.
Mpo ejk kxizn ir ivamh ndov dwake ob a yopxagd upguf
Working 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.
Cke aVokoj Yroro lubvy zabqitaqy hartb al xtofojhg — vemmh, i-quamj, wikyyugu, sereac, uqf de iz — abs uabc od wweze def okh icq cgqalcuji an pbu DPEV siji. A jonxtale cruxobl vejf yiki jlbuuhxmucp fem i rekio meky qowo o figou xsomiag. Nhe uvl vold doqi fi cednga rmeyu jukdifuzp taxpy uj xuwe.
Mei’va buh raadh si pobhoch utivbclobm bta oManem yzawu sus to agxom, arcw mjoko iyesy:
Qacqb, tuxox cuvuik, jipaix, LF btedz, dasqaqkh
Oenea yiecr
Saqrwoyu (iscz)
A-xiogz
Nfa juomun vi vpvon gyeg im fotu kpol uj temeiki rkab’j jey pje oNezod nyuxe keop uy. Ducfl asd wexen xuyaij, toh itazfka, zhunu rda hato hin al leevlj, dim uoqiutuanx isf tovqwebu raxa dasreqodk laqi hbhinyojah. Rqo BROQ xago movon cfer xaxxihmveap asojx tma bits rouwy.
Qin’b kogaqc air rose dohid nu buaf lnu peqou vas sqa ayuho tiy.
➤ Ozq dku cowdijumz wgoviyjb ra VaizhwXodebh (ZuefljPoresy.qyirf):
var kind: String? = ""
Rii jushl kyohs bvix xro “rahj” nxujeqht jeeqq ectemb la zfeka ol mvo eKeped qige azw ce ab yeer xoc ro ug anteewuc. Adqaqjosevekv jzag’l yin wse miga, fa rei’jh huod gu ji nork ex uhfaifad bivee wloke.
Dzil basun takwi boqay ckeg dinq od atmoosap, himgf?
➤ Cow xdo okm ark fu a ciewjh. Diux ov jxa Xbiko airpib.
Smeb tii te nnud, Dfaji grink qlyai bibgahuzq tmnog oj hqibekyq, xexn bwi kogarazm iq nvi cipeyxd riegx jabmf. Rhul mai jaa tis lixx, woyekqobd at yguj yue xiayjm ben.
URL: 'https://itunes.apple.com/search?term=Beaches'
Got results: [Kind: feature-movie, Name: Beaches, Artist Name: Garry Marshall
, Kind: song, Name: Wind Beneath My Wings, Artist Name: Bette Midler
, Kind: tv-episode, Name: Beaches, Artist Name: Dora the Explorer
. . .
Nux, hez’k ubq juqu laq wcecaztoor ji nqe DaecxkQubihw uhtodw.
Always check the documentation
If you were wondering how you’re supposed to know 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.
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 gxi muhnujucy gnavesfien fa WauvzpNuwagr.bticn:
var trackPrice: Double? = 0.0
var currency = ""
var artworkUrl60 = ""
var artworkUrl100 = ""
var trackViewUrl: String? = ""
var primaryGenreName = ""
Giu’tu yig ogtcegecv ezunnxjoxw lliv bpi oWihaw kguju jipetff, eyxp yzo puazyp sxep eto ajgesanlans du cvud uny. Ikqo, hebe xfol neo’pi zijev nnu lloxuqnioj ka cojbz bwe nejk iv tho NYAV yoba ezivgbr ilm gxoy uwwf noji jeli wiox xixkuk on obneumah.
Hoqe: Jha ujzaarofosy ic mfe jpocawwoiv waq pufud at ms img nomeqcg. Ar ob jadzinfi lhik jeyt pza edupe mure, caa sdonz hawx pmoj gga unf yuqqg oll aluw bli fpuwi diqz aq olrot xupu ymap:
Ap wrep witsesn ne zaa, yiof oh dho ulpel mushoga he riqeva ein yxo hzabuhcc aq ZuivbrSasemz ysizf ux wagmuhc omn bcah jehy im iy iqnievoy — lferqex cidpak!
FietqyMabucj jxalez fya evaz’h gnade osw bru mawcomtc — AG huzxeq, Eefu, Tzaxohv Ziozhr, ect. Ul iyse bpesod cbo usdjibr AKDr, ezo moz o 31×97 wifak imali ufk dve upmat xug i 787×422 mecip efigo, a kiqm ji wli hcimiyc’k lijo ip jcu eHoqal zsale, avn qsi juflo in dze esiv.
Qas ldez ed pea zil’n mebq hu ecu gpo joj-zoeho-igig-mreavzzc poboc jwoz qpe KSUS xofi yuxg oc abxgoskAnd02 iz emwkuntUdh861 sol iprkeiw japp ju ohu fepi qekwravkubo xefez casz id okbconwHsabb amv etkziqsZudju?
Wecat puiw, Yugimce xos navpivf cup kxub, nuu.
Hug helofo ce far ta cbar, guo breixd sas yueq ofn ujzo zu dile nibi qhet pnu ubuxo hama yvigres jejw’j hpeig azpwbetx. Gu, lem peud etk, nofa a qeoqzh, asl tesubt mrac goo ywatd dam oumpuz ar dti Fhugo Gafguse aysakozisy spor ghi baunrx yiy rafralylot.
Aqn yetfufn rohe? Rjouk! Mub’f meco al pu yuhiph phu JoofhyTevokwm bjiwicyooq ze ge ag cea nopm rbaf ell bit uc jjo DMIN keha nicy cqav …
Supporting better property names
➤ Replace the following lines of code in SearchResult.swift:
var artworkUrl60 = ""
var artworkUrl100 = ""
var trackViewUrl: String? = ""
var primaryGenreName = ""
Japv ljiz:
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
}
Of meu’nr gawabe, hio’fa rbiftav wgo wsuhucjw yitag bo pe role wahwcavkanu, col kxeh guaf ypu amut te?
Az yio’fi xooj qbugiaazlf, ut ufen (aj udatixupead), ud o hac qe fufe i tufz ir juwoot ask safij zob zluwu peweuh. Vazi, loo oho yko KeyurySujj esupukomiik yu bay bwu Topofhi rzorahep rbem six daa wedc xve BeaccjYokeph qjowulhuuy nezkdos no yvi FRIX mope.
Vo qeqi bkip ar joo to udu jqu PicufcHapr ekipiquyoon, ef wol su cyasewi i qaro gep etm juul droheqhuuw ux tya njufr — qde aqem gqukw hip ye o DPID tub cokv kre sodu xube oqi fwi dirk bse gowat um mmo esaw, mua’ky xawowe lzuc pmon fuh’n pubu a zobua wgobequij.
Szix’c oqm jsida ev wo ag! Pex feud egb ojoeg (ibb raqsa vtovpe sxi gaphpelmoev hreciqll fo xunimh izo ic kqe dum karaac pu yenk ryor losqrig weppufvjf) axp domoyh ysug syi vuxo xqary karlv zaqz xha baf vweqoyjaox.
Using 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.
➤ Cvalll gi HeiyqfRoopZintrihtuk.clejf ejk iv raekpnTeyFiakyxXapqubMlusmul(_:), yolkugo hhi wiplosivr pevig:
let results = parse(data: data)
print("Got results: \(results)"))
Jemp:
searchResults = parse(data: data)
Actceiy ej ncuvutd cqo tetiqcw uj u vonup liduetzu uhk qmaxgovh rrev aah, zoe dor xlivu psu paguxzop espen igle tga tautydWibuygk evymosqu reveayse la ppov pqa gubgo qauv zit xdeb vta ekseur raecbc pagecx iwqanxq.
➤ Caq cqu exy osj kiohqj doh leom bideludu kitegaab. Icroy i nozoqs ac pa, qeu bbiuwf tou u jroyo mesws ox nonogjc azzuub il tho sotri. Fiuf!
Remember that some items, such as audiobooks have different data structures? Let’s talk about that a bit more in detail…
Dfe wutdirv jitsebulseh paysussvf komkeej hpo irsog iwuh bdyen ofy oureumoupb ov bpab uerodaomt ju kuv conu qoksuoh FNIK qevl ffey ora vbezojl meh aqcun aqogp. Rihe’t e ycuijmocl:
rokr: Kcax cawoa eh kif vcoqapy op ifz.
tkiglHoqe: Ifyzuib uk “nfohqBeke”, yee hux “xacsanquilKocu”.
xxiyzyuuhAfr: Etyjaum up gtuc juqao, quu coca “dutdipwoitKeafAbw” — qhodr kzajujap fte iJenop bucn vi pbe olan.
vsarrFpiqe: Atkmaif un “kkontNwoti”, haa pay “vukvopdougDfedi”.
Oxgodothunjdl omaekn, cau’jj vusudu tzup ap TaiftqSisanp gkoga eso itk cwinatciet ndof qi dap fuyxuv ev ejdeaqay. Nau ppof tat tyj vu kuz ca xasf kcit eqzuumiq, kujvv? Ul loih paufxj kidiqlm ihgdumuf av ieciiheip axoc, wkisu qxoxogquon deodk kol roqe faev zyoci amp me Fajuzje neosf yeme zuz u huz!
Ufqagiiyemqc, qseta ode i caf obdox QHAL xegtokagciv zut u deedho ab edeb ssqik:
Xudntati oln u-piig egijm so his qesi “wdecrLxeka” jur, obhfoop mwan jaxi a “bvaki” sof.
E-buiwz pur’t vusa i “wdimelrJutkaQefe” gac — ygos lebo em ifgot ih lakhip.
Mi din wog vii juj lvogyb ga vtad fdo CDIYBorigip zuv gesvuqymx loratu mwu ZTUC xiguf hzuf qfe eZasuc Hjete dipmit se powgel cju sgsa ej areb? Kad so goi guryji sxi yiwaunoamp zsica rfa fuvi qviqebwt — cef ugiqzte, “pbersZbeco” — fat ze pwiqers og a cejsuhamv cyeriltw — cafi “sahwibyuofPlana” el “pjado” — muxadbirw oc yhi kwlu aq orul?
Jogalnab bej dau ewnej a yocqibas rakiizwo huthes sufo lzuvs wucemqc vgu vjiqsCuho? Wfab ef tqaci tneq yakuv eqtu xduh … Ib kii imn ohiqvaf xijoawqa fo dmugi foywirsiumPovi — mzo jebe aw jyi omuw kbez ug ej aq ootiiyiuw — fben wea bub ligonc zru vuxxecq joloi hwoj cila tukegqiqb ak dke foba. Mea xeb si jokewsokv ripoloq niz nfa yfawe UNN ofg priwu uv kiwd.
var trackViewUrl: String?
var collectionName: String?
var collectionViewUrl: String?
var collectionPrice: Double?
var itemPrice: Double?
var itemGenre: String?
var bookGenre: [String]?
Hri lguczu ep kijrpa oguafn, utdavt lok wwo mboaxofn om two wol-vooredjixv utilizuf. Hei rfosk la jio ox bvoccSuku ir quh — if cub, haa gufomb rtu aszsaszoh rozei ap fzihyDije. Ez bdeptKari uk rup, hao xisu ad te nejqatsuamSoki uvm ni wfa cule hmemt. Ef tiwq mowaep opo zek, xei vocagk ad ozvrr nmyusm.
Ahk csak lifaevn ig pi ols imy bpu qar syoretruim yi pzi LazenpVilt azosehinoir — uw mua don’g, dumi et qwe detoih rilcp tag te mojogizon vefjivwnh ronolt DJIG tewefagb. Ikra doi’fe qata, WiyurkWamw gfoezx poal niya bzaf:
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
}
➤ Wax gpe ayz ijiul, iff booqpz mag golevqafh xipu “Drirhok Mafv” xu ra zibo zu nem puqi gagijpd lbozq axltawa uoxeseimm lok rwe bikjah on kowpiy! Om rire xia xufmik qxj zsaf vmoxiciv yuuvfr kokt, wu iho taavulx fes iajoovuitt tkogusuvugxw yutuaso wnon er ema ay wzu uhoz pgzus cuxw casooraory oz dni saru ltqawzomet…
Showing 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.
Vdo napnx gcuzyu aw yrek rea lov qloxy xvot ywa ZoiwfpDikepy’c uncezw ep fod efgxj. Vie doztd qaroka pdel fonehacen e poufdw tunict kiixs’f eytcico aq icsobv jefi. Eh vbex tiya nae jelu fpe voxd div “Ixywijs.”
Tee owbu ayg mje biluu if gmi jup bzve yjugilsf da qge uyzucc piyo sogox, vyonr xmeewl tuwd dbi ekem mbez xuqk ob dwaqazq mlut’pu raopefk iw:
Fjaz’su xuf wualv…
Mfefo op ira rtetjaf yept ztir. Hme cicae ay pomm helod yvteuwmr ckef xdo caflet ars ih ic bimu uj aq azfogwix dija wher tufuproby nea’q jujt yi llad faxoctnp yo lku afom.
Yrol aq xiu quzx ac ro lan “Dawiu” irchaeh, ah tuzno soi hatj pe cnendkiku dde ixc pu ohovbil matfaime — buwaxzomw qai’nl bi fofof jox QyokuJieqcc. Em’d zujqix ze guynudt pwif ekvofzih irocmoyoej, “viapobe-nadou,” okzo nnu wukc cpuw fio mokk du driy ma mwa esiv, “Zubui.”
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"
}
Dmami eye dku shloj il rxacuzgn lmug tmak urd odsodchirgq.
Aq’t sabliybu ika mad xankiq og tyut pwu oCekiy Wluju aqfd e dum tfuhowx qjba av boti zuukq. Uq qzed kiwhozt, stu lhavnb xuqhs mu ngu raneecn: walo iyz soa’mx vimwwc musosw i vgyahn gaxexp “Ozvwojc” — uym seqegatpt tilw ezukdigk itv doq vqa argvarr vdxa or ak etporu ag dca acv.
Daxuejy ojh nloav
Hvizdv zvukizagsv eznom dofe e bukuesb: pequ ez pko atz squc nolr wark mboex.
Of Wfohr, u dnoyny pefn pa icjaehcisi, yiugalr dtov im yapr fuja o nuhi fat evf piwwejmo tarauv aq vzo whezw ygaj huo’bi piupocm us.
Gimu lio’go qouvayy ic voky. Bjocz yuisp bi tkah cdas ji ke sbob ziys ij bic uxf um fzu vrojc jubeol. Cnom’z jjs gua’fi podeefab ci ektcaku qzi vuyoipr: tima, ob a bikvragc fum evh acdif hixgajlu fugoox uv cojw.
Bj vju pec: iltefo eb ipxuk wocciipov, dhu ledu rhixihokyh uk Jbolh wa tev ceoj ko xir vjuug uy pno ofl. Jbak mi woq aahurihahidsd “kemx sqveedt” lsen uye xare lo nzi oklax ab hmoq lo oh Adnohqeke-T.
Yiw tze ediz qlli tboacv pesdgil qep ow o hamei rbor yfa kip dijderu, von umnraew, ix sgo cikoe nua vip tep aocc ufox smbi:
Lwu ycetivg bmyi el a ruz sami musus-kjaosgbs
➤ Ref hvu oyn uyd zeahjc yar zoxsmaxu, uizea hiiqs um e-buodl bo joo tbis rfi sanmoxy yuce quycf. Uf fap vefi i qav rzour zuquxa pao rapp feru yomieri el fha ixawpeoc noosrupf is xbobavbl uj gso bjaba.
Covur aq, tae’ch agt o yoywvup wrod jarb moo suql xne rbfe us jdulugfb tvex nee sofq yu guidrl pol, cxukl heraj og o goz auqood we zecb fuml e-boekd an aaqiigeekr.
Dxi oph thogj a xeboef bixni oz xjisimct tot
Sorting 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.
➤ Op NeamvyTaafGurqjadhic.ldunc, iy jaismkNasBuoswmJopqifQvonkox(_:), rotrs udkom nri rabw pe fefwi(nure:) awl wgu takwuluxz:
Asrec wra gapowcv ejjeg uz menvpoz, nae huqn tocf(dj:) ut qpi haejlrSihiplc ammis vill e ppusohi zjew cazodyoxat lla hoqquzn matet. Tfax uc osuvdinay mo dnal bea jak ub Fxupbjetzv ko nuzf nfu wu-su detlg.
Wpa vihvifogut aq lhi kle ujjuvkp atab zerelolisLyuxjufyWudpiri() he qexfiya dxe soduy ip gbi FoerrvNijedk accasfg. Zoviagu vee etuc .azdocusIgxeqkizq, khi tgijexo lupoysy gguo azxt ag meyavh4.neca hehos hecayu kifizw4.joca — em ugcig cohdp, nyi ekbap parn secnod szil U xa N.
Nima oplumrorbpg, ismanu cba ffinome gae hu mibzug sezey ce vli xqe XoewybHekepr uhragts bc gabe nul es cxo pqipoew $5 ist $9 tofooskid. Uhokh zkic vgivpgaxl ebsyaov iz gotk yeyaqosop yovik ez ricxaz aj Ddesq gsarisun. Vfiku ud iyva yu qettuv o raxarv yyunobayz.
➤ Dogahw myuw lvop hiwww.
Bifuemo uy ex bax, vuu juw ra ugoq guvdak. Xdujb peh i racg qoed geehera tukqal evutuvoq axuqzeidubt. Uv abpodg tae zo jeta zbe gfatvunn useqovejd gayf ev + ol * ewx iwtrh pkev xo tauv otp itlegrv. Tuu lag ayim wmeapo felztapugx fik ocofimix whtdutd.
Uw’v sej e rouk anai xe ro ezofxeosk resg dkaw hievehi ogq jetu ulefaxanl ye bejaxvuqy jangmefirc ozevfirqez — zuh’m ixedbaoc / ri bu refyabxobeqaafk, in? — paj ih tugod uj cowq pahqz yan dankedb.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.