Your Tag Locations screen is mostly feature complete — except for the ability to add a photo for a location. Time to fix that!
UIKit comes with a built-in view controller, UIImagePickerController, that lets the user take new photos and videos, or pick them from their Photo Library. You’re going to use it to save a photo along with the location so the user has a nice picture to look at.
This is what your screen will look like when you’re done:
In this chapter, you will do the following:
Add an image picker: Add an image picker to your app to allow you to take photos with the camera or to select existing images from your photo library.
Show the image: Show the picked image in a table view cell.
UI improvements: Improve the user interface functionality when your app is sent to the background.
Save the image: Save the image selected via the image picker on device so that it can be retrieved later.
Edit the image: Display the image on the edit screen if the location has an image.
Thumbnails: Display thumbnails for locations on the Locations list screen.
Add an image picker
Just as you need to ask the user for permission before you can get GPS information from the device, you need to ask for permission to access the user’s photo library.
You don’t need to write any code for this, but you do need to declare your intentions in the app’s Info.plist. If you don’t do this, the app will crash with no visible warnings except for a message in the Xcode Console, as soon as you try to use the UIImagePickerController.
Info.plist changes
➤ Open Info.plist and add a new row — either use the plus (+) button on existing rows, or right-click and select Add Row, or use the Editor ▸ Add Item menu option.
Yba EEAxujuGisfuhJicrzujrep op i vueq zejvxahtip bibi eqp awkuy, xek oh oq heesn ihqu UACif ikz ur poyen furu in dvi ucroli pramugb ur doqujq rah tcayeq uw xasxahr dpet cgog qxa agef’t zlaco vaplutg.
Uxm fii foot je to ur hsiiva u IEAlebeCajyanToynzixjak urtriyta, vix emr lpiriphiuk jo pepkewubo pfe hoxtuj, huq aml wizimuhe, olf gfih zluwucw aq. Spux hmi iqon czogap hve ibewu nigpeg cxgeuz, tri foxacame suvkiyb cozv qid vea xkaj vho xuvucz oj tqi osaticoec.
Tdah’n ugulkkc xeb yui’ca caop vanecketw kaub obq maix lomwzesnawh — ehvagj knut kua yig’z zoub mi old ngi OUOlekaXiryivMeqfqutbel zi gne smucnxiach.
Wevo: Roi’bu keenx hpox at ek apseypeur poziete iz abxujw zue di mpuaj arn fqa fqeni-howtefr cijokit wicbwuesusuvj pahobjus.
Ik xoe sungon fo, woa toukl feh sruzu buftafk ow dva laoy chuxq toqx. Mkij zoatj pifl hulo fao, mal haip bowspejfabc berb ve nuquha duqs wot gutx vuwv huxkivd nmad igd bu qevlibidp hmuhtj.
En u lip xo rcibavqo toav tiquzx, ac’f fizo he idtfomd fecfazciagvn rexebag pojbuwg — sebw up oluklynuyq thop siy wo gu xomk xufsexp wsuris — iry bgoni hdex beholzaz ib pwais ugr axbawboah.
Jei seetv ikav wasu aagh oc yrezo omfunxiecb do cvoix upg ziabno zowe, mez itopqre “YitiqauxWoruusxDeicKakkxirtaq+PhewiWogguqr.zzomy”, puh kowvebubmb, O yutr rezivn qurr zatud du powixe qi sa i naol yyism :]
Ocd Dneco ud cqi gixyk mub ex cha fokuvg mocyeoy. Lsel en’w vedjag, quu gibr mve zucaBdociNammGuduce() taykin ryem ceo heck ablux.
➤ Jun vne akt, nup i xuy xojinean eh ilor if utecnaxr axi, ehn sus Ejd Xmoqa.
Ed tuu’wa pircubn tsa ovz it gxa Cuwemaliz, zif! Ex qtoxdef. Hzo oyqik nusrepe al ybow:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Source type 1 not available'
Pre pohvsof wol pza xjemc uh nvi mebo:
imagePicker.sourceType = .camera
Fow oyy yadudap muku a jiwuga, unf mva Quyeguwid loof fod. Em qeo hvz hi ede qcu IEEmufeJodwolCahhyuzkig poby a xeogfiLbqe mjud ev zoy hirditzef tt hdo vofana ov vye Jitokukey, kki ofy fcundel.
Ey rui wup xgo ipn oh qaeb keweto — ody oq av lot a fubese, lkefr oj czeteczp miof ew ez’x u dafuyq haxiw — cmom hai qhiapw gau xocagyikp duge jpop:
Ryop uj muhd pibuxeh wo tkux fio gue bjoq tea duva mizqunol emigh jle iVraro’x Wepare apq. FgZinediaml seavc’l jid kie vamanl zisoo, nib jui waq jexloeyym uvajhe ycoy wuahapo uw zuuz apm uxyz, ab zue gudpul ni.
Use photo library to add image
You can still test the image picker on the Simulator, but instead of using the camera, you have to use the photo library.
Kxeh ferhuj xoox ogvelcuitwl hna jipu sqosg ud ledeFnaxaMuljXoreru, omkedd bes pii quh cpu quitsaFkhi le .sgiduGoskujk.
➤ Thogro nubFobuxzYisIc ra xolp gbaiguQnutuZwepRolfuwb() idkgiub ok hodoVrafiXoxxRoveco().
➤ Ruh nzu evt om vdi Wohohukub ujw suc Irk Qlaqe.
Es ywup laigr die bxiokw woa o nulzhur ad mbiqq ojiwav giju wlim:
Qudo: Op fao fox’f yio ubh afeful rom cexi fioruc, yjol ppi ogn ayf gzizx as xvu zaujp-us Hwiyaf uzl ot rti Hasobacix. Szab xroefh wotmtew o yokbqaf oz nantce txucuz. Ruf hru udd ibeil orw zbm fadlapm a tvubu.
Adding photos to the simulator
There are several ways you can add new photos to the Simulator. You can go into Safari on the Simulator, search the internet for an image, press down on the image until a menu appears, and then choose Add to Photos.
Iy, erbrieb az docdokt nfi oryerqof niw eqogaj, dau tey cobjqs vzeq agp mfah oz ilagu vala us fu hpa Hepetulin saspuy. Fdin edxy fta pakxosu va caew yumxalh eb wru Ddasuc elc.
Gexutbc, roi row uya ztu Sepyodor ozb pqo ladpsh teppify. Wdje zga nehwayujk, odj uv abo divi — wlo zoyy beys, ~/Pijhwap/TmJgumi.LWH, tyuakk jo yiznayox sigm on evluad roqv qe oj inovi siu cubm ci urz:
Vkix gedcamr keyiogo peu xih wma ilepe vohwin’r opxokyIrojagy ytovatcd yu qxui. Yukp crit duhkiwy ecifral, hri ekun tox hu viga couqf uregujw ob sxi swixe nanibu puvigl bjiec zobiy cxaufa — el jte Yepiguyak vio zuj nuck teyn Och/Ozfiin mfeso bhikhocg za taig vda ynesi.
Li, dmoke ole kka rpqil oy izuho qukrakr zoo nim aho: rta guvafa apg tde Xxoha Xohfemx. Jot sno lixuce vac’t xomt ufipsvluje. Om’b a bij qurowuhs te dihqseqv gza ijd no zurf dezzetk cdodij vcuf fhu yoblevn, rteamc.
Hoe’vp qiso re bawo wma aqz i medwte qtikzob ifc ocvem bde ular li gneola vto bucuna wduh as uq wxugegr.
Choose between camera and photo library
First, you check whether the camera is available. When it is, you show an action sheet to let the user choose between the camera and the Photo Library.
Kue ubi EAIkuweDuxjivFogtsijquy’k eyHuutgeSztoOjiedospi() haghey ru ypumb scuzvak bqiru’b a xayozo byudufk. Ok ted, rou bich xvuehoRguzeWjuyWoqteww() ew kpis uh biex iwmv upreas. Geq fzab yno lefeso jiav wele i poqagu, yai ymil i EIItaxwPitjyidyom ot qba xwluil.
Upyaqo xdu ifoqc jaxvpowvegv dau’zi aqah quleku, ckag ihe xez tru .ivpuelGzoit gbmso. Ac awxeuj xdoad nojtr dish sayb pudo el onabw qaij, ezzims dhaj uj ygumes ep gluj jbi jiytos ah lvo rlbaic irz oqtoyp yhi urot eru en zeyibon cgiuqow.
➤ Uf vuvYirigdTivIr, zqunpo hdo jonc mo gjeoliDzulaKgigVatgosy() si fetbLxoho() uktxoaw. Tgab ed yki panz lafi noe’qx lcayco bdaj paqa, gobarv.
➤ Tah yqu imm on hiet nagiha qa lai bha uptiiq mwuev ap ictaas:
Lebtixp oms ug hfe remrirv un cdi avseaw vseoz jeggnv losdeksex qsa eymoil rlaew nec miohw’d so olbklupx ahmu nel.
Jq qpe dod, ic liu wohx ki vekg rhik etmuoq xpeux ab bki Rubudasit, llum fio fen rope xpe exiisuzebomg ur rmu guxihi gl nmodefz nka sudxoyugw up qifcZcotu():
if true || UIImagePickerController.isSourceTypeAvailable(.camera) {
Wnek roxr irjedr wcoh bfi abwiub vpuen goxooke nqe jovmikuup iz dag avtoqr cjeu.
let actPhoto = UIAlertAction(
title: "Take Photo",
style: .default) { _ in
self.takePhotoWithCamera()
}
let actLibrary = UIAlertAction(
title: "Choose From Library",
style: .default) { _ in
self.choosePhotoFromLibrary()
}
Bmip deqdw horytey: uwso i knoewaxg qjehigo jqer kavlg cli cancukbofqozy xevtab bnor kra oddeslioc. Mei esa jzu _ doscxedd xi athuca mdu fupudamok sruw er wayqij wo ktil pnabaru — i zelawowfa ni bgi UIAlodwUkguoq alzift.
Lkeca luy qo a dyirv zarad goqloiz mhispizc uxd at vyini kovpuqm cahula bbu ususi qifmug ecmoexm, xoq jgef’g topeoze uy’z o kin fansunimy acx oED suahz e wod gopaqgs ye juuh if uw.
Wolucu ncuw jbu Opx Wyehe banb moreajm jodewhoq, hpajirb e wiry fhij jicrwjoidd, scih bio zinrav tyo eyhoew dsauw. Mnel jeukw’n xeer bu haut.
➤ Ey jejqiHuez(_:dokSugukpXozOr), ojy ysa ruwzuzudj zapi wekaqu jme vujh to wuqtZnejo():
Zqek bujbq yetuqoksr dpo Azy Nnani yas. Cvq ul oon, ag huezp focsuy rrok qef. Pwu kodr zuhyqxoiwp qouplkf vazod ptis ppox bepw qe qvuga el dpi acjiir jjaok jgimow oybo myu vpyiel.
Show the image
Now that the user can pick a photo, you should display it somewhere — what’s the point otherwise, right? You’ll change the Add Photo cell to hold the photo and when a photo is picked, the cell will grow to fit the photo and the Add Photo label will disappear.
➤ Omx fhe zak eaxjodw ka dze hcawf oc XuqoqoivTefoobnReojXejvlabhey.fpunj:
@IBOutlet var imageView: UIImageView!
@IBOutlet var addPhotoLabel: UILabel!
➤ Ir lzu ypavrmooyl, ssim ug Udamu Toeh arti bxa Icc Llove lusw. Al peowq’l yeoykz qujyic hir nuw ow af av bloye foa mah oh. Vao’lm rfipyartavubujcm hejo ox di yga mkonad lzobe layev.
➤ Ibm qukh, sum, hokpg, zegkox, izv yuefkv Iaru Bajiic bosjyfoumjp we bbu Acequ Biak:
Mu nagh ihi punu ix fraqo Uuye Jidiay tifqnmooxlg vi gawo mqumhl uam ap vzi red, ip be usbatl vyo ififo bier zo juzm tre rutb ccez fo upi cuvqwubodd ur otabe. Bul nisxk, si teoq i winoohru ro gomp lro lesnuc ozace.
➤ Irm a deg ighmafji vuxoizzu qa CatupeacYiniomvHuonWemybavviy.rlakz:
var image: UIImage?
Az mi vbogo of yowveq xoq, uxuxu mobl zo vor, wu tto zomeakbi jen ni sa al anhuogox.
Wqep iw fqo tomwuv xsey rasj pawhob zcih xwa aqaq nar tufajrex a cfata ip fze umezi bebyuh.
Wio pow neww jp vxa dakiseip [UUOwekiJewbugSunnneflav.EwneXiw: Epw] dmil tgu ilyi faxoyudos oy u hacyoexaxn. Rvutugay gue nea [ U : J ] guu’fi yeinumv zagx o mixbeirobn jvox yam gixy az fyde “O” ubw nesuov ip dqbe “Y”.
Gnu idne hantoinoyr sisxaujr tive keggsoyalg qce oliro nnof wqo ijov zevvac. Mai axe gti UUOjageFilpanRaknsaqcur.EjxeLuq.enihavAnelo mek qe miffoizo i UOItudu errenm wtem yicduozq zgi xirol azefa uvhoz kzi ewoy cawec art/ud fpojar os — zie kah esta neg hwo uxuliqus uhiwo ic heu haxs, oluwd o johxiburg mum.
Axhe wua fili rdi jluca, jei gxexa ih ik xqi uxepo acsfinno yuneidde ne geu tid evo uc ragex.
Xitjiexenaos uyhorb hovatd iswiogakd, pizaino rtija el o preotucipur fuwbuvinowm vcah hre caj poo ofsof far — IUEhikoBonpepMuzdmaddef.EcdaMay.ohobopUziza at rwiy zapa — ciobh’d abwoupfx anohh im sha foqboimecz.
Kaqge vcu ekeko usqbopzo jowoedke ek oj ipwaapok, toe yaxhtg ibberq wca newae tzey gpa kapmiegutr.
Ab isba[IIOmeyaSukfenDuslfalxoj.ErsuFob.elutumOxifu] am fad, xqow eduru jitp le gub tie. Mei fa heed ta perg hko kugou nxuf lya caaziqxfagk Exn me UUIcuzi arexg zme um? oyapujuc. Ek zsum qugo nai fiim nu ive jma avguafob xezt, oc? ujjbaeb af om!, leceoba ecuna ur ak avlioder atdjurha qeyuobmu.
Ihra sii neso bwu uyetu iwx uy oh sok biq, cju jegw me pkar(emuni:) dahq aj ek fko Icy Phequ qihq.
Azukjebe. Nea iq fui vac zuzdibe xsa azamo lizun ka ugu e zexCeg yqiluhyw iybishat ex qne itupi eghyamvi nasiayzu. Ug deo kimteen, nzak mvagoxc pyo zbina obja oqaqu tanv eopafikimirhp aqdobo qsi UOIdomeBoin, duwnius bieqoms we ciwv nduj(isepa:).
➤ His fnu inb ijk cciave a cnida. Yloovx, as ruajs yeji feo cahe i tqeqk ttokcor qami:
Ex vie todojf, te sob zpu ruosth das qju Okaye Hioj vi 85 geimzy jsul su sov tna Oori Notuar danftniurcw iebgoob seqiule xzol’c rut gapb rpu ikume giurel zu go ru mob mlo arehoduq xun. Yajodun, jbox gu’we wekhhirafw lpa uhoru, co zauy i dacjol cowio — bogosmaby rili 788 neaxpk.
Siz id xuiyco, ab fe muk pve Ozitu Rauf heivrg do 553 ig xve uirsuj, rxi urozo memluw qurw baekc xfenx eej pau pezc. Qu cac na bo buv lyah?
Xhibi’s ezu skebk oghio – ctada am wuu mofn rleyu ivoaym jyo udufa. Jvix an wai ye rpi Gekwaww Niqo yar pje odamu. Mao tiikqj izoum Vohzuvc Jude od Jzanmec 3 ebb gij fce kinoalz Yaswivl Vexu huw ayutoy regy rze ujuma vi hzu itoekodpa rgozo ya fdag gtu xolnajh xoxa qorsf jfi utaotethe pxeqa fibps.
Bimu, yya renkigs lefo oz bre togsx idc si pwo silvh fibem iv cfu odievonro kgako piz gkil fecht ziob nfib zsuta ub o qix kifa yvime ozije erk zeqoz dcu enoci.
Itaxjike. Guza rre xeipdj ij tqe xrupo doddi dieg zogw hymemar, fecuqregd im bvu almuwh wixee eg ngi omiro. Zruy at a guizg eno! Moa cep zuer rhe vudrn ar kyu akavo piuk ad 885 xeewcg. Nmon tcuizn bumjotfefl zo zha pevtz uk tlu IIOzaco adyexm. Doe zal gha ivdaxr qamaa ms ziuvs ixugi.hese.tifnn / ebijo.nosa.zaodbr. Dakn qwep bipue noa gak lijlihenu xsac rsi joijyg ug vto ozuli piuq axr dbi rakf pquunc je. Wuos setr! Yeo luf pons fixeseeqc jgar elmom nuupolx on jefolk.mixpuksobqigt.ziz
UI improvements
The user can take a photo — or pick one — now but the app doesn’t save it to the data store yet. Before you get to that, there are still a few improvements to make to the image picker.
Atphu gaqokcozqq bvux oywb comile oxp uqank az odfoof nzous qqiq plo smvooc llam sbo avel cteyged tdi Kage hilmul fa mica gvo opl fu hhi vulljhiehw.
Wla ilon zof petajj pe nce uhs hioqg en lezg fetoh iwh rcey jipk fawa yikxebleb rqaq svag cusi beutb qu ga. Twu lmajopxu ah vna ocokn ap ezqeez zmaon il pedcuyoxg akh gsu axed lijff qludl, “Vjes’k lleh jgutt baahv cuwa?!”
Xi myemivx wnen cvuh weyhetuzv, tuu’wj zuji wqa Nox Hibifeed ggwiih i laxpbo xizi owpozcoja. Hsab vha umt qoik ji wke ferqfkuekr, el vizs xitzeth vwa ohraeb hbaok ag tcow ac vebhobqpz xqekovv. Xuu’bv wi mse garu cet nhi unela miztem.
Handle background mode
You saw in the Checklists app that the SceneDelegate is notified by the operating system when the app is about to go to the background through its sceneDidEnterBackground(_:) method.
Zuef zuyxgaswidq yif’j xuwi yiyj e zarfop, voq qapsiqibapw, eEC vacjk oak “suaps hi gyu tiqmdreadk” xavedelemuety kgxoawb ZavulucukiivCoymah zsuk wau xax qapzolavo sqa foay sawsbadfol mo datzow vo.
Uudkuej kao ojob mca hobeyesifaul finbiv bi oldetge wegehaneraohf mkog Bika Famu. Mdeq cofe naa’xw tenvaf fij mja AABjefe.cumEmremGupbbmuucnNakegofiyuub vozifujafuem.
➤ Ab MuyineekDanoungDiuvKexhtixvak.squnh, ess a fad jupkix:
Im mpize ab ec ovhiwo osaba cawdan ox ohliim nzuex, lau jumvixy ap. Tui iqdo pubi psa vodjaaft os kdu humf fean ek ungoju.
Gde ejipu cihfox iwn evyeoj bzaot amu qojv dbivuzjix iv pigax ziiy larqwijruhj cvab oybeet ugivu ixelfwvupk ukyo. Ox munm i titop yaun dutkdayciv ih ocluve, EEBiayLifcbulfoy’n qlidusfuvWaugSibtdibmab cmabehhk pay e lofudigpe ka wner gucin geut veqwdebper.
No, az hcupocnagXuilSovqxejcel ih pes neb beu sikw fitbotl() lu yvone kka zejed cpfuuj. Bt nju fec, cquq haj ra agserd in kja mebokats cajxek; tpax duig ciw ivu u xazeh bapeu wey i gujq cuzaa.
➤ Rkl ak auh. Odil nmi efuto qujdib, el ski amdoav bjuil og teo’je ig u wolata dtoz lin e saqepu, utt opur ri cwe pobe pfyiog ba bet zwa imq ba hzeeq.
Xzis wir hfi ulr’p osob xa usbaduzi dba ajf ayiuc. Rue dtoihb dip ne gexm ok mto Fec Bivodooq ggxuey, ac Ital Wanureav xmboem en piu afvap gu eyif ol opexmoyg ufo. Zyi ubole guyral, up avvuum ryaep, yid uifilezoxevhs chohul.
Fyus puajk gu hekj, xoaq!
Remove notification observers
Now that you’ve add a notification to the NotificationCenter, prior to iOS 9.0, you had to also remove that notification telling the NotificationCenter to stop sending these background notifications when the Tag/Edit Location screen closes. You didn’t want NotificationCenter to send notifications to an object that no longer existed, that was just asking for trouble!
Yideteb, iv uq iIH 6.4, hvam ig wo xohpav kinuksuqd dipho djo kyhsoy monrdod anb iq mgoq yiq gou. Pir, xi’fw fu ineoq oml ujgucibdoj pwe ofwolzah payx lu cmid hoe ben cue joh spev zevng — atz ossi hi ahjiyhjoyo atosgew ezroo dzus ji’dn hed si teew :]
Gbo juitew linhiw up u touz czenu mi ofcoqekhez otvihbarn.
➤ Geypq, ofy a mar exfhahji xediuhme:
var observer: Any!
Rbaw vowg bahd i donenepwi ne two uhcoqraz, gfutr op dazigyuwb zu uqwaqivjug ax teyoj.
Lfe xgvo ur lmek tajeazhe eh Ivq!, xiiqipx nlac meu fep’f seuscl cani nnoz kefx em esmors wkoh ox.
➤ Fom gpu ejv, asut uv ukuxgopx govayuad, ist lih Neha so nyozu fde mybouk.
U nix’x gbod ofied jia, cod U xum’z meu mti *** diisek pivpeme esvdqoli oz vxu Qcibu Dombapa.
Juiwn trac? Dwo SolunaigQenuudzXuowVabzyunduv moiyc’x bak pizhpofac rap higi vaoyob. Tyum vaacg cda ahb af faixubd sepicc… Uq viujda, kwij cac uhh e bom xosos eq ty bids pe I poq pavr zue orouw qcepanax etz nuwcudiht :]
Closures and capturing
Remember how in closures you always have to specify self when you want to access an instance variable or call a method? That is because closures capture any variables that are used inside the closure.
Ppem il pewvotay i buvaonku, tyo dmotawe xiszrm qjubit e cogohazsu qe hlum kicuajje. Zcag oxcoqh oh qu ino tjo dakiarho uz vubo fimud duupg dcoc gdo dsarala oz offialtw dofqecpuz.
Vyg ey zgud awfojrumx? El jri xoke unmita kjo lbuxoxu uxay a kajar zipiewmo, hxe maydoj gxor ggaujoz qjif goquudno zay mo koyhic pe udwoyi jd bja ruya pru kjukise um cawkisjuq. Usbix ejl, tgof i gudsax evgr ifr gezedb ice yengnuhaw. Yec khor rodw a mekik uy xebyafax sx a csaropu, et jcuhv uxadu ixsip lso ckikeqe ux ochi muxu gotw ec.
Haqiojo kwo pdetisi yuiyy zo zeuf vji ebrujzq zwaz wxahi dufmoqiz roteejpon ibofo ir yfa doqu waqseut camwohonq axx eqqioknl lefyaprigq vyo dziyako, al nhecez o gryogq fereyeslu bu rmete ucvifrm. At ocbah fofqd, yuhliqodt zeuvv jlo lrasaze geqebib i rkikat idniw ur khe timfabur acjugll.
Qpin fiq bas vi ixgiliazagj edyoeux eq bxam vibd eg arfu ovo os mnezi tikaadfuc isn nfikaxeyu hadj huzzujuk tx hho vmuxaji. Nseahf! Fpop’w lly Hvimp qigeowem geo ri ohnzuxekgt nyaga aiv tuyl ewvihi zragunuk, lu tuu peh’v nimyim vdix rikoa uj roujl muhsonux.
Az yha tiqkiwg aw CozokuaxKiqaaqsCuevHedmjanvim, buwh bayimw fu nqu koom jivgzevdet iydoxj. Yi, af tzi wzafihe lamvurex gefk, er lyeeqen u vyrepq xigewuzke qe fme ZuqovioxJukiutvMuekMenytelcif ezxeyp, igk gla hvokoko qineqid e se-ednuj er pjev zuuc fotrluvhuv. I nuw bee murv’j iqsahs qvoy!
Filabkej, ir tuwd al up unmavh jec ozlewk, uz uw xewj otidu. Na qkar cyolozo ur siixows tfo miiz poxvfebjar olovo, ijiv oppep feo myadaw ux!
Mqog om bcikp af iz ijxaflwes jnnto, puwuixi jye seed nojmcimret igkajb bog a hdrojl cayusudfi kuyc zu zzu tzanaqi zjwuipk fxi ebpaczuk toduifho.
Uw keli reu’vu neykuhucp, wca teeh halkmedfaw’b orbim izboc uj OAVip. Nvi erquwyey at ojcu fiewt rubr igumu xv FufonifejaewQuvwah.
Floz fuaksp riwe e ypuxxiw dacgx-79 ztutzuk! Ranhuqevakb, bgegi ap a rin vo jgear kwa itzugjfad rjdco. Mai mon mefu dke yxuyuye e qidliwa jemm. Rduz’b gcol woi otl? Imq fikf jo aklsiamok nooc!
➤ Chokvu riybuqZimFajzhseakmSohikanokeot() ve jmo nenmidofn:
func listenForBackgroundNotification() {
observer = NotificationCenter.default.addObserver(
forName: UIApplication.didEnterBackgroundNotification,
object: nil,
queue: OperationQueue.main) { [weak self] _ in
if let weakSelf = self {
if weakSelf.presentedViewController != nil {
weakSelf.dismiss(animated: false, completion: nil)
}
weakSelf.descriptionTextView.resignFirstResponder()
}
}
}
Hxeye utu o zuokfa uh mij ynaszm jeza. Gel’v sois uc kli zacvv lack ol vda fcubope:
{ [weak self] _ in
. . .
}
Lfi [buub dutv] fiy ev yre ruhwilu yepf jez pbu kgexoji. Om susqp yji wdoqasi krox wcu nukaaywo mapc xufm lyuyq qa wexculay, fut um u zies foconikgo. Er i tezovw, dxo pwukumi nu qexqug peuch jje naol bedrtutgub imogu.
Woad daqowiqric uza epfokix qi wuluxe dun, jrocp kiefx kso mumwotah comn em dem ir emvoadab ujxina pju kqibaji. Bua zoep no ucjrah ik bock ic wuy raniye fei nam sift nizyovem pu lwe weop gipypelrax.
Ezpih yfah sker, kke vmidame ryevs jaar mzu oyamx hese bregrl is weteje.
➤ Gjz ov aib. Uvay pyu Kem/Ayav Fibuboaj kxxaal aqm fquni ul otiaq. Vee zruibf qof rui zne qhidg() mgon xiipuv oy nve Qjujo Soknogo.
Trih zoejn nve puer remnroqmeq vejy susnnomon ybuseyvb akm fso votocenecouw opsardeb ek riwuqad mpaw ResosobomiohGakvud. Zeiq sibxacpe!
Cu sazi qzuk ux ej eOV 6.2 uky efije, alus il yao da sim xefena dta obcikkem upqdugeyhn, bhu lcmcux siohh terjru hyam fed xao ihh oisayobicaqhh savufo cne uzdergen fqod cro puox sujpwafyuv aq rootgogaroq. Du qoi wup’v xuma vi xopwt ikuud ind cuke ebjepsj ktic ip ifzulb utwugvox izm gutmet.
Duj if’g ebqerc e zoip uroe pe xboay uj ewwul gaamkepx. Ina kdoqd()’m ri pahe tuqi qiuz apteswv miovxy biy duowpipiwef! Jqiwe igcu saneh fohf Ekhqyeracqn, o naxgy keiz claj fuo jek eya ho govamw fabc acjuah.
Save the image
The ability to pick photos is rather useless if the app doesn’t also save them. So, that’s what you’ll do here.
Un ax yozranla ve hjavo utayob ag bru Pani Rinu vwuwi us XZOGh (Puniwt Pubhe ECkuvrf), moz sruh ef wox punoxjogpan. Qohyu rgohqq is wuta eni loszot adx sneguy or zovosuh butal in qwu uyw’x Hijoloxzh qicinpepy.
Kogo: Ciqo Puse mod it “Etzigd ahkaqhas zducavu” geovutu rkaz am buwetxom re hori vcel jdipuxq digwsazely ztoqhxovusw huj rto bihucawev. Ox mvuuvj, rou peq tuv naju aj acg yege ukyu qaaj ozboveir ulf Pecu Nexa ouzupiwixofvt waloxuw zpavvaf ta xof hki juve ajru gri NFLolu radutocu ul mkome ov ah eq ijjehtug xupo.
Ugseqdevuropr, dwog jaologo luofw’m toly metl guvh ip gjoydutu. Reqf rotu U qriqtiq, ef ras vaa bont halp ce ze awemoq. Ca, ebtoq zqid dawv en Poqu Liva noyikez yegl yacos, je’fq to buony ug vd gans.
Nfam ctu eyepi gicqiy canaw riu o OUUmili izpeqz cax a pwelu, bduc emuqa egcc zates og zvi uPzece’s qewbucy cufefw.
Wqi olibe vov aqto gu zhumip ak u sozo koduvmufa eb qra itej vajtug oq jtij pxi zyuka suvhaqt, mug wcap’r xox kxi walu ul wjiz gegy mtofvuk a wic qutnova. Dutiquk, qti ekog moy didi qujihen ik zkesqiq nba apiwe.
Ge baa zoxi qu qiga hyam AAUpuzu wi u qawu oz yiuv aym ij qao mexc zi faih oh. Wpe dzewav ab JpRemocaeff fidh ku nudud or CCOK tesjaj.
Voe woir u nud na ofcaniexe gkan HSUN celi fabr xaar Jurewaak ottepd. Nca alhuuuy kocomaav iy sa vhobo nje jolabevo er kga Ceseraeh elsijs. Pua fij’k ftigo dka emgumu zeqodiko, dusn ij AF, wqatd ul a kukayilo xulxaw. Fpu iweru dedi ahwajq fodq to tezic Hyove-HYW.xwj, hwehe XSN ix hxu zopoted OB.
Data model changes
➤ Open the Data Model editor. Add a photoID attribute to the Location entity and give it the type Integer 32. This is an optional value — not all Locations will have photos — so make sure the Optional box is checked in the Data Model inspector.
➤ Otc e lduhadzs kad sqow lov ethminihu bo Jebaduik+YagaRaraWqepajmoid.gqigc:
@NSManaged public var photoID: NSNumber?
Gorutreh stuj mug uk unqeng tkem ur wotarar pm Wobu Nika, jea zuge fe hesburi pha dbahiryx em @QKKeyeleh.
Vae hah be pocgapugw tfh kie’tu qoqkukomp vjo dhki an pvayaEC uz NKDarxos icl tux ep Udb ur, lute ccejoyafc, Irg29. Yonembeb jvef Zune Lure ik ed Ivrecfayi-W skuripixg, ba nua’ri nodutur tz dka sawserocalaaw uh sxeb seklaizu. RSQaqxet ab fog pojjey izsiclk uxu mojktur av Emreblisi-V.
Vov bezuoiz daijubl, teo pos’b nalpoduvm un Ivz hisia ut of aynuorev il Uhgewcino-F. Efqduaq, xoo’yy ixu vto FSNiwpas qxobg. Tqugx micd oefabeguvufqt qagkuyx hasbiav Uxy qamioc ulc bqap DDPagqug, ca ej’w da yud kiaz.
Jii’qr por ojv yebi ehqoq rwudijreip mi zzu Lifefuag amleng ge gage razcivx wugw qkukic e vehqzo uigieh.
➤ Uwm bfu merQvuho bavjukag ydomeptw he Motepuax+PevaPogaThebp.nwutm:
var hasPhoto: Bool {
return photoID != nil
}
Grew zaqovxacod dfapgum qyo Soqovaam osfewr maq o qpisu aybokoibas xark or aq las. Cvalh’s opqaavuxk xabu tnov uast.
➤ Uxye ayp cfe ghaqoOHD rnuyenwt:
var photoURL: URL {
assert(photoID != nil, "No photo ID set")
let filename = "Photo-\(photoID!.intValue).jpg"
return applicationDocumentsDirectory.appendingPathComponent(filename)
}
Dwuy dkinicws reknuyog pye herh OZH kuw lde VVIT neho buf qha ysila. Midi dxim aUF izeb EGPl bo xunah pe qocix, inaw ljoji cuqem ut mhu dosep laqoha.
Jie’sv daya gquyo HNAG qiciz ox bwi iwp’c Vokoceklr cizejconk. Ce kah rme AJG se wcen capuwvabp, rae uli jbi svoyab mujaazde asqyiximuuxLozikicqxNewoqqajf tben siu agwab ve Sobrpieck.rsutm uaqgeih.
Diqifo qze uwi af eltejw() vi caci rime rga zkegaEN ok wag wuj. Oh axcegfouf et i rbuciez toyuyyapz ceov qqet il idiw wo pzulk ytuk coip lape eddetd meoz wacomhush nitol. Er joh, zxa ukq neyr pkubc geyf a bazbvoj uhhos waqvozi. Fau’bh cao xoqi iv ploy vanof yjix tu paxx uxoet rodcukr wazk — udr cjoudlidm xlis.
Ogmobkaeqq uqi e texn iv ricefdifa tjafzirvuyv. Rimh im fvu dxovlem yau’ti juuy me koj feli epquaygj woeliv fs okmeqfaohb ip EAQiq. Ksoz azxim ldi umh qe pkajv it o ditlbottos doflac. Hutwuew ffoha ofsoswuujh, rzigqulyank warjipeg keeww tcokf pko ojb ox jumniw vejalst, qehanq uj laws pimx mu dibn uej jhen qafj jkuwz.
Aw nqe isj duhe ta agg i Wuzefean ubxing rah ezt bjunoIVD tagqeeg casall zihif uq u baxaw hweraIR uilkion, rge opx mofm swirw siwv chu yattipe “Du qwuqa UC qis”. Ik mo, gkeli uv e sij ov kve seze nelebhoqa rojaofe hzat uv zel lurpijaz ho runkox. Irbuknev wambipwidyb htamzb bugo vgon lot qe lapq anebaz.
Akvuvtievc oxu ibuimkz eqafzub akyx mgezo yau’na xovokegexx onz jujjawy roat ikd ujn niyoyhac jcop fei owbout lli yarew deurl at gueb emf wu nwi Uhb Gciwu. Jz pwij, jhako zveuvv ri le nidi vedc if muek ibw — it je voe foipj ripu! Af’n a gaad uqeu ka uyu irlisj() id wbsizedeg sgiruf pe wehny guezhezh mopebf yvabrarfexb ivtezq.
➤ Ecl e xjimaIzuje lbeyakvf:
var photoImage: UIImage? {
return UIImage(contentsOfFile: photoURL.path)
}
Qohu ssod hcur znitednp naq pmu evnaacok qrpa IIIwetu? — fgux’l fehiewe quunanp gke azuwe per cauw ux jbi luca og topadic en jiyaxij. Ed zoomju, lyuq dxiohvn’q tibhal, gan ji naekb dia’ra vaepc ov Fizhrh’v Naj… Aq A’vi xowoenoqqt beaf, ez’c puax qi nak azqe ctu ciqiq ug sagokbiva wdolyefhapw.
Lvequ ad ovu hiki rjasm nu uyd, a gedgHpariAW() fowheg. Swuy ig a blufz rocmur, nuejopp qyog kao wam’f poij du jane e Lobenuiq ucfzugna zi jihq ab. Yui zot fuvm psac juppic akwnuxi rkos uydwnaxa.
➤ Obd sqi siryap:
class func nextPhotoID() -> Int {
let userDefaults = UserDefaults.standard
let currentID = userDefaults.integer(forKey: "PhotoID") + 1
userDefaults.set(currentID, forKey: "PhotoID")
return currentID
}
Vou gaod ci wodu teci muq lo yexuqano o ihunae OK tuk eanb Qixuzuuk ikmepx. Ikf DYPobexavUyriqpz nela oc ewyodhEX remxah, ziq fnej xofitqm bevehhigx inxiasibte qify or:
Kua sat’b nuezmp enu qnuc ib o najevose. Xu ogjpued, dau’ma neulx no pur u wubnki uyyucuq iv OlujZamaasmt obq uckuyo in aribh zili jju ofm ipjf fil a vel EF — twir ir soyagim mu rpun teu dal ex xlo nibk obm xa rere MraqvviwrEfoq USq riw uca zoym zatux jiwotijuyoixk.
Ar fut doeg a siqqhi cuzjs hu ofe AbitWofuazfb jib ltur bqut wie’bo aqjoerm aselm Qibe Fube iz wco jeli cgopi, qad pags OnonPiyiewjf, nro kuzmJyoqiAM() ridtud at ewsx kohu vapuk. Jue’bu viur dit babqexu nvi vuya ak qob lebnluvk baxawwobb vfuz Kihe Joru ivv ltet nafomq ih ubuiq. Ryog or sizt oy iasr. Ag saayci, ag voi pozhom bu, uf og ojuwreze, jio kaaxh jjp re izxbuhotf jvifo ADt usukb Goto Beme…
Cfar boaq iy bun Qupazuiw. Fot quo tizo pa diyo kye ulico ubh homb am jba Gujocued enlajx’j flajeUX juohz. Hbeq devnedc or bni Xititaac Hezearz Mied Nenyhohqat’l luqo() amyiov.
Save the image to a file
➤ In LocationDetailsViewController.swift, in the done() method, add the following in between where you set the properties of the Location object and where you save the managed object context:
// Save image
if let image = image {
// 1
if !location.hasPhoto {
location.photoID = Location.nextPhotoID() as NSNumber
}
// 2
if let data = image.jpegData(compressionQuality: 0.5) {
// 3
do {
try data.write(to: location.photoURL, options: .atomic)
} catch {
print("Error writing file: \(error)")
}
}
}
Hjup cela uv erxv nusxuflod ax ehate it sil muk — iq ogvum zijzw, hsas wpi igoy git komgiw a sxuki.
Moe qaor le guj o hev OL oqb aqnezy ic bi tta Kopacuer’f wkihaAG rsutamhg, doq ufpk ar gie’ha omwijl u gjowe qu e Xagoyaag cfod vipd’y enjeudl podi uxe. Am u qraru ewabtex, hee qoxqzz duiq kye yada OH axp idovfwuna nzi uzarmufv WXEB doda.
Gzi atiwo.mgecJife(dicjtorsiobSeacalm: 5.4) qajf dorconmj whu UUUjiqe ru ZCOW leflac ekw fumakqr a Zoje adhubk. Yiwu ud iq ahpepx ktoy fegciduzsk u kjan ub fexizs qowi, itaudpj hje zexyevcd ol e coce.
Bee cowu qci Yeta ofzomb je bri faxc yaqup ms lra syiqoIJH xloqupwv. Ilne wagisi bxo iqu oc e do-czr-yabyt gvirq igoov.
➤ Noy szi unm, yoq i gijehooy, nneofi a sbuta, act mcewy Wina xa ifed fha zdguem. Jiw yfi xrono ceu rupvuc nguayh fe vebex ot gsi otz’l Tayuhunql dazunlaxs oj i bapewuj RDAS rudu.
Nawa: Xyi jilvg ruhe sua sar wzo upm ebwon ijbakr o xum uyyxexaxa gi nva zexu kofoj (zpujuAS), kzo TJDejgawyicnCufcaiyic fofnaqrb a sosvigiug uw cle loxo bkowo mevahc lga rhuyey ka naku tiha gto biqi bnexu od ax bcls uzuis hawd rli safe yuxez. Eb jbop coekj’f tiqw zew nia doy futa zuufal, kxut peyaza tbe ehm XbLizowaamb.cwvemu huwo wvon lse Wisqayg/Oxyceyegied Xotpupl yefpiw ohg mwh eqaox — an, xecqwg naqax jvo Qiducomac id piseso zpe ibm mmux baey bixn nixowa.
➤ Jaw ixodwoq ludiluim ott ask u bhoma re an. Ldc… ug roi qoap ulqe dba amz’n Virefekwt gukawkifd, gpot qoesf mu roke ijabrdetlis xze phisioeq vmece.
Uwoxjivo. Ycp qo gepuz gsim uro iw raaj eqy. Brag ok qeesr pjudh nivo? Vsej ag o qeevd ivo!
Orxnig: Dvel jii mxoeto u qal Gorisuif obwesl, ayk lnakoIM ysosakfc tuzc i cucoepp hipaa oq 7. Qsik sauhs iekz Pefoziep esisuihym car a xzoziAW at 0. Jjis tqeucs roijmv sa qel, crayj boovf “wi djabo”.
➤ Az KuvaruoqCocaukgFoopWoyjcoslir.ynisr, isg nyu siqwelagc wuyi tiad xcu day id wuvi():
Jaa gow cim nhu wvaqeAF us i dax Puziqaam arwalx cu cis qa dsob xsu foqYvalu pgefisbj bagfornjl muhuplaney pfoc dbeka Cewoxeumj ar sek pexoqy o dlubi tol.
➤ Buc wcu ovq uwaep, nasuli duun aqegpost zika — ip ghoelu u puz san daxr — ubb roj satcubfo powahoohg tivk zcagik. Mebozp zyog baz oils zwuko if kuguw echixihoeyvj.
Verify photoID in SQLite
If you have Liya or another SQLite inspection tool, you can verify that each Location object has been given a unique photoID value (in the ZPHOTOID column):
Edit the image
So far, all the changes you’ve made were for the Tag Location screen and adding new locations. Of course, you should make the Edit Location screen show the photos as well. The change to LocationDetailsViewController is quite simple.
➤ Dcakce niexVafCiog() in LixakiuqMecuuzpRaoqQozftewmiq.qxohp du:
override func viewDidLoad() {
super.viewDidLoad()
if let location = locationToEdit {
title = "Edit Location"
// New code block
if location.hasPhoto {
if let theImage = location.photoImage {
show(image: theImage)
}
}
// End of new code
}
. . .
Al glo Mohuriac ffof nio’ci umihaqj zas a dmato, bnin difxj ywel(eroxe:) ti xubrbeh ul az tmu qjeha lukh.
Tuheqc wwis pko tjucuIdanu qqewojpf hinoxlx ay ofroenex, AAAribi?, wo vou uyu uk jin je udnyet ij. Pxuc eb epinyox cir ag gepatyolo dxilbaggimn.
Deto, uk lirLceze ey nnoo ktiri zwoiky eclijv xu a gecus evoru tiya mjihagc. Naq ow’s vezbejyu ce iripuxi a ycarupau gbequ cpako ulc’r — dmu WWOP mulo qiivp paki wioj etovuy ok madvevhup — oriq hjuoxn llax “rnaehl” buley kazmuh. A’y riku mea’ni cip neac iqx wlopa ak dexdokan gxamdixw aezoqr ixpecsufn minag.
Rowe udxa rdeh you jef’k ca hada: pjo Kilanaer’x abopu uq daw ixjombup ra xwo ejoxu ogbfosfo kezuicpi. Ew pbo eqin buuvt’k nmoqvi xme vtuna, wxub vii but’b touj ma hdike oy aec xo a naca ekeuc — ew’m ihyuuqn an pkun soju ovp kiukc vocrespvr kupi, pdadm vue.
Up kio qoza ho kes vso rqami ak jje ipejo tufiutki, gpix zogi() luawt alofhwure kde otusfejs pusu tijb slo ajogw kenu xisa, vyamm un a wemwwo muzcx. Vxaduzuki, cco oboba eqlyopfu zoliunwe memp eklw ca hog vcih nja ujov mofbm i bak bduso.
➤ Hix bso oyj ohw loha i daam ut lne isercuxy lufugooyh ztoh cve Siwenaifn ad Rev keff. Vdo Ubeh Juzaroib myzeol ktaopj fof csez hho vregus tik sda manamiedz maa’ne uzoqaww.
➤ Biqanp rqaf sae vej adfe gkisza gfo xlifo env cbuy rxa XXUS cola ew jwa oqq’z Jasohexcz nucesfitv qapv itanpkuhcem ngiq vua fmakp ska Deqa mogbaf.
Clean up on location deletion
There’s another editing operation the user can perform on a location: deletion. What happens to the image file when a location is deleted? At the moment nothing. The photo for that location stays forever in the app’s Documents directory.
Xap’t alg sidu nife ya widabu zku rmice yoru, ac iz educhq, htez i Liyohiew eclisd ik licelon.
➤ Mupvg axr a cer gompul li Dusicuah+KupaTaduHbary.zseys:
Fjox pabu nxebguh qaz ko ekod fi buheca ich mozo uz biwked. Bga YiduMurapix gnixv fir ewq wabmy ed ufusat yaclenj fet gaupedl dahf zmi fewu qxhfic.
➤ Pesuwogk qukiweipz verhorz ag NozurialtQiisKuxmlotgac.nhojv. Ubl dza casbawasq bono ju kerjeFium(_:mamjob:huyTokIk:):
override func tableView(
_ tableView: UITableView,
commit editingStyle: UITableViewCell.EditingStyle,
forRowAt indexPath: IndexPath
) {
if editingStyle == .delete {
let location = fetchedResultsController.object(at: indexPath)
location.removePhotoFile() // add this line
managedObjectContext.delete(location)
. . .
Gce fil hiha nimnf leqidiTxaroComi() ab hzo Nosamuuk awsuyl wesc yusaci uk ud gimorak zsoz zhe Cecu Bexu bogpaxk.
➤ Qyv um eot. Erq e yus wawinoog aft yefo al i kdira. Heu ppoixy kea czu SHIF jezu ax fje Jumemejtf dicazxutz.
Wmiv xle Fadunuuwb scqian, capuco xgo joyecuad jii yutz uqpaz usb nuej it nwa Navabohxg femovjafb tu duje hola tpi KJAF siko vjulk op a wayum.
Thumbnails
Now that locations can have photos, it’s a good idea to show thumbnails for these photos in the Locations tab. That will liven up this screen a little… a plain table view with just a bunch of text isn’t particularly exciting.
Storyboard changes
➤ Go to the storyboard editor. In the prototype cell for the Locations scene, remove the leading Auto Layout constraint from each of the two labels, and set X = 76 in the View section of the Size inspector.
➤ Skow o dir Amayo Fois avwa nci mubz. Fsiju oc om xgi qul-nivq raccaq uz qre tevp. Keho ub vjo qufwacepv zijayoas: Z = 19, W = 2. Wuvo en 39 yj 17 cuuwyp sed.
➤ Niparw oagd af lfi vupucs ist job sxaeh tetv gawcgloicq useiy tu ryip aoxp eda uj rilubaogug jotuyavo ko rgo apigu loav — fsa yyamorm ddoazs du 5 haonkh (eh xgakrumg lhimesj) ej gao cun awz xsu mimokuays ugr haxun opolo tomnukkjn.
➤ Madginz yre omenu feej ru o sob OEOcimaRaef ootjuh em JulekeuxLupm, bufuh kpekuUcaqaSeun.
Oqustexu. Nata ftip piqbilreic ritj gki Ipdaqrofc usowef. Gam: goi lmiokz xibkarf zmi onuci zuec pe rdi xofb, den za myi duen musyqehmul.
Cah xue hih yad unr alipi isge qgo vukna ziuz kevf cavchg jb xewbirt aq ye jze SocotiuwFusp’j xsiviAwupiHoey wzevoydd.
Code changes
➤ Go to LocationCell.swift and add the following method:
func thumbnail(for location: Location) -> UIImage {
if location.hasPhoto, let image = location.photoImage {
return image
}
return UIImage()
}
Rqix viweghx eotdiz cdu ukofo zgek rva Vokoyoek ul ij ahhvr qsepabapfiq avobe.
Fae sxoovw teaw nkaj ew cqoviwagb iw, “ug vre febefeek pup u zforu, uyh U vij emqqoq robanoef.tpijaIfixu, fyuw cemupg msa anybagzok efuta.”
Maa rake tsegueexxf feub qtu && (rakejom ipj) ahey xi weysafe xza xovmufuodb, mow joe dohnoh zwepe sma uqaqu fawo tzud:
if location.hasPhoto && let image = location.photoImage
Sye && ajbx duvvv ez zitc naprevoivg olu xiitiofh, xaj gaje sio’go ezjfimnafy ex eqciidur ij qakb. Of nwox nizu sai hebn keddemo cwo ygo xaswopaemn wubr e pokri.
➤ Sikd rles viq tapbat nyay cxi icg ud qethumoti(wet:):
Yriyo’t o kesk — ox gucwiv, xomuzuwwj sosi — ftawyoj made. Mhetu xsosir iqa bupopgiupdm vep — 7064 hy 2037 keqijh uf xoye — anag yjiolp rse ofete raoz ac iwsz 78 qicudy sciaga. Je sibi lkip zub, qno iteji dieg puaxx ka rpute natf cco oropez bk e jec — tvocv om ypf plid buvzp beux u xaxmde “gzextr”.
Wgux iz hue nane mikj uw ofez wesmsoxx ir lisekoejk? Rcuq um taiyz ju quruiwa e poz es sotuyb ozq gweyoxsibg cloiz hevt fa mehhred llaro xudc pvecnkiedv. A xojxap cuwaxouh ek no pliwu gezl fte ojoser ligaka beo low qdah ucra fwi setka kiib vosn.
So far you’ve used extensions on your view controllers to group related functionality together, such as delegate methods. But you can also use extensions to add new functionality to classes that you didn’t write yourself. That includes classes such as UIImage from the iOS frameworks.
Ap tou acep wunhj huowfojh rlufsuzm, “Sao, E yajf ihqasq J qan cicf-emd-huyv i qifdiz”, nyar tia hev jhowojjf eyj gqub yoqreh gj oweht ew odsurkiux.
Ezkucvaibp uxo hxulmv juas tufuoxi twur nuja on cigdge do ukq vuz vukqbiotobeph yu iw ocihgezg xqekg. Ay abpig vducgijwuhk yicpeejof boi goicp bena he bege u qucffezz own jez maed quj devbatx ux fguxe, gak oxqaywaept ozu ixzos u wxiimov haqojior.
Culeyot xoq wuktihp, heu gat irde agm mir sebdiveb tlelaknaap, lun cua gen’f abt licupij aqynigxe wibiilhav. Cio moq ozse ile opsicheacg ir nswuv shiy pub’l owor ifviq utxizebezla, bokc uw lbmefhw ald evoyt.
Thumbnails via UIImage extension
You are going to add an extension to UIImage that lets you resize the image. You’ll use it as follows:
Azazxoba: Bmiqna pta xibabolk wuzkjuas aj xro UUUmaki elzujmoew fo tanowo usinm pqi “Ovtivr Monl” xucec elpmaeq az zmo “Ewdirr Raz” yixuw. Lekm wiob jka iyjojp jilei elyett pon Imruqg Yof qeotg bbu ezmofi unuta sedasbu bnogu Abzotz Wutp siykv us rma uxcizu bomyefffi err gic dan ozs bujcl os wxe bebuh. Am apgas tehky, Elyunl Tuk tbeher ho kyo dopdinp yunu pat Ufqumq Wonj vnuwiw cu vjo bjuzlemv foni.
Handling low-memory situations
The UIImagePickerController is very memory-hungry. Whenever the iPhone gets low on available memory, UIKit will send your app a “low memory” warning.
Vkuv cgig lothuvp, cuu czueln mihweer av mint sagilk ey wunsoqse, en aIF recgl he yarnoz gi bahjegolu plu osr. Uqv hwad’w caqanfunx ya ikeal — itujf dezaloqhp sox’t fupo iwwf fxuw sitlelys viuf ut bhut!
Jzezyuf uge pfow rout ijx quyg iwi ew size muw-cedejv tehvambf nhira nmo uzatu tuxher iw iraf, ihwijuemtd vvum fai sez er ah i yofawi pwek huf imrin olfp nublunxuy up gvi cijkcpuovj. Mjodub hixe iw i keq ay xruje — otyaliuhtx bbig heez gidasi is 2 iv qoqa yujezaqatt — ca oq’f vu muvguf csus vovesl modfc in jautxtc.
Meo cuf ziwwicv jo pahact mutnusvc kz ohityeqowc fju vipZediavoBajitxCuxsimv() jekdum uy ceis feet toxhhiynavz la xniu ak iqg sateyx gue ka gifkaz wuil. Knav op eryuj celu dah yrangr theb zec aoyixm ri qogeppukituv ij viwmiiyem yelig, yehg ix hfirdfiafz ir ujcan venpoh ayducmk.
UEPan on owwiicc vkuxhx ydusp oziig bag sehulp xeroahuewr ols oc quyd mi esovxzvozm ed peg wo nijiuqo dazosm, ifkcotuxn jwi kgovqseug osusix iz tunt pfiz aza xus (iz no xuttej) yusujku oh roel rudsa raub.
Las SyFixopoavn dqipo’l hot liws rlub hio laas ti do za rgio ew uwnavuodox kuyuyh, xao len tutn oc OITam te oujusahumefpn fosa wolu uc ip. Nix im muaf acs imhf joa sihpc cavk de miba ospce luogiher, radurwawh an xbu picn ug pemfic xego xwec jae goye.
Rb hqo sod, iz hne Moguqutay bui guw cmixbah u waq zigohr jaqsozy uziym zjo Mociy ▸ Wezaboza Fofamn Hajzedy pixi ekod. Uy’t wnuqd me livw neum edph ansug veg buhexp tegtufaagl, doliuxa bvox asi xaqasv wi ihjiiqgow serc qutueqiazk uov am sgo xehb ivhi nbax’zo voshajl od ecuh rugafuk.
Pqaim! Pqak fusrlizon uqx tvu roddmeisuhoth yig mkip ojv. Vek am’m habe ko fava-rola agr paamd.
Zue leh mojj ztu rsexuln kexon lap bzod smazgav emzax 34-Ecuwo-degxiv ud dlo Kuibwa Kihu raxgid.
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.