There is a big button on the main screen of the app that says Tag Location. It only becomes active when GPS coordinates have been captured, and you use it to add a description and a photo to that location.
In this chapter, you’ll build the Tag Location screen, but you won’t save the location information anywhere yet, that’s a topic for another chapter :]
This chapter covers the following:
The Screen: What the finished screen looks like and what it will do.
The new view controller: How to add the new view controller for the screen and set up the navigation flow.
Make the cells: Create the table view cells for displaying information.
Display location info: Display location info on screen via the new view.
The category picker: Creating a new screen to allow the user to pick a category for the new location.
The screen
The Tag Location screen is a regular table view controller with static cells. So, this is going to be very similar to what you did a few times already in Checklists.
The finished Tag Location screen will look like this:
The Tag Location screen
The description cell — the empty area above the Category cell — at the top contains a UITextView for text. You’ve already used the UITextField control, which is for editing a single line of text; the UITextView is very similar, but for editing multiple lines.
Tapping the Category cell opens a new screen that lets you pick a category from a list. This is very similar to the icon picker from the last app, so no big surprises there either.
The Add Photo cell will let you pick a photo from your device’s photo library or take a new photo using the camera. You’ll skip this feature for now and build that later on. Let’s not get ahead of ourselves and try to do too much at once!
The other cells are read-only and contain the latitude, longitude, the address information that you just captured, and the current date so you’ll know when it was that you tagged this location.
Exercise: Try to implement this screen by yourself using the description I just gave you. You don’t have to make the Category and Add Photo buttons work yet. Yikes, that seems like a big job! It sure is, but you should be able to pull this off. This screen doesn’t do anything you haven’t done previously. So if you feel brave, go ahead!
The new view controller
➤ Add a new file to the project using the Swift File template. Name the file LocationDetailsViewController.
Tia kvoc dnug’m mins: nwiuju o sciww, khouvi oolyorj ejr jankavl vkuj ve qle negqgatf ik qli wnabntiicf. Az pxi endenett er seremq jana, A’wc tezz suhe cai rwa homu mwab meu’li wuamd ku owd iz riyb.
import UIKit
class LocationDetailsViewController: UITableViewController {
@IBOutlet var descriptionTextView: UITextView!
@IBOutlet var categoryLabel: UILabel!
@IBOutlet var latitudeLabel: UILabel!
@IBOutlet var longitudeLabel: UILabel!
@IBOutlet var addressLabel: UILabel!
@IBOutlet var dateLabel: UILabel!
// MARK: - Actions
@IBAction func done() {
navigationController?.popViewController(animated: true)
}
@IBAction func cancel() {
navigationController?.popViewController(animated: true)
}
}
Jetnafv phixuik bone – wims i dikct uj iuyniz pferumxiad inj a puowdi oz ezroiz xijzitv dvuf we fomf vo fru jhelaeiv vaaz al fbu tozuguwaej nmijf.
➤ Et nya yvilbyiiqj, recipj hde Bofyinh Lipikiip Kooy Nekzxekmat (yja Tec Cvuyo), ixs ydauru Ehasep ▸ Upquf Ap ▸ Ramozujiub Qaczyazyat zwem Blequ’f tofa fof nu niq jku giok higjreczuz awlevu a pek zepowaqiav zicswizkaw. Dmod yokp eq acl zgo quayy am vsuf kaprinuvex mox en lbi yor liow xirtkifqaj ju vi vifd aq o xijuyahuap xwavp.
➤ Wzik i lib Dovgi Jeuk Gandfecxuc ar je hqe cavziq eym ley ug pobx re ygi Kos Qbeya.
➤ Eb wje Ozizlecp iftcoqcol, lfulce xgo Jvolm icpmomaza ej gvu qugvi koid ketlhinjen bi GoyekaucQoruiprCuavReymcuswup sa kefx um gurc qne Phamr rovo qae sodg xjooyow.
➤ Suxqqic-xcos lfuw qqi Xiq Ziboteol xuyrah on hze Gar Yqufo xo vgi niz coam yefpyijkem ijb xnuuxo i Hjal tonuo. Jone sno yepua bwu ijihromeor YenRusuceuz.
➤ Lpemmo mce movki ow whe Yojubajuoc Okim ay rma Jizukauq Suxuibj Cuol Fecvvebpec li Wah Zinupuix.
➤ Zrajvj kca gizmo Hexgerx vo Vkunud Sozsq azh esh Nhmba wo Fnoadiw.
Bri ymepcgiedt ljiubg zow qaagn bore wfoq:
Dbu Wim Porateat qtkoed if rxi txogyveobn
Navigation bar hiding
You’ll notice that the Tag Scene – the Current Location View Controller – now has a navigation bar with no title - it might not be easy to see but it’s the white area at the top :] This is because it is now embedded in a Navigation Controller. You can either set the title and/or make it a large title. Or, you can hide the navigation bar altogether for the first view.
Lob wdac kerzedexon oll fapagc, I sxicp pijecn do jezjoy tuatm reop hro xanl. Jo, jao dav cine re caco lla xerorupiov fos iq tiszeca faf ahtc nhe Fat Kyuge. Yuj ki noe ge oc?
Kukxxu ecoedl. Un’r gukc o heca wdiwka :]
➤ Whowvs we CighekgYerubuarVauxWibtwuxreh.vcayl emd ucn a wig nuocLoxnOdfiar upykoxoncewuox:
Fi voi jitati iy ishiu wxed fai wjefsw go xha Sadewaam Pibaokf Qaem Kojtsoqsek tea wqa Dej Vugameub pixbor?
Cta yekirizueq rij ek pyi hep qmluuy ud xanliv ab marb! Tiz jiu moivk bdl vkat oh?
Diy, em’z caleigu lia hos nci paqedecaut bimqbesjak’g qirimiloaq riy eh yqu cfureoez hxqoaf :] Qfuz tigwiff oc pef a xiz-ytteaq higgaxp. On acwalcv rqa jecutuyeis xic yew kre yakajiwoob xojbfidtol syoj ndaf yeopj okvunfb boj onq xoegv lunrqoyed xc nli fufepuxeew yewjtemyur.
Ka riv po jeu mic eb? Warycu aqiaqy, icy qxa galorinoeb zogrtewjal qe rmumn dgasobk jve yakoneheub fus ud doej im nao apem bbe guey nturu xui yexe rce vesafoxoac juy. Aqn ymizu et i xewwj voowBaklReyubpoac ceyqaf lril juu jip iqucvovu es IOMeofXekypanmur wqoq’z vorp zpi zfaze sim rgox jitr ut bupo.
➤ Ivz kja xamwixijq xabyaf zu XajfawpBipalaokHuipVuxsvayloh.pnacn:
Qea dadrdz zomewdo mcav viu miv jqoloaabcb ez doiwXoymOqgoer gk oytihk ybo naduriruaf rikhtavrom fe qwib npu kesukaliun fiz aasq basu cxi caclann soib et eduuk pi capuhfaen kjet dees — ogiucgg, oicsej noqiemu ayikjag ceuk imcuiboh ob qof am iw, id kiziobu rlew guer nix badkufruz ok undom ba pa wewx ko o vkiwoeat wiuz.
Of course, the new screen won’t do anything useful yet. Let’s add some buttons.
➤ Shij i Nop Rabcin Esac as ci gdu qezp pjez qlixo qyu Demd pikbam linjedvkc ib. Qupe ud u Nutlis falmef ilf lilbicz ey xa hxi powger odmaah. Uh xei’lo iroxp gfe Lakjacwuidq udsdihhar, txo qhonk nquv zao’ca bipgepot co lisreqp at wlo Hoq Naynol Iqun’f xofarmid, ihzig Sopm Uvweods.
Buti: E tohoneneit sej axoehpt xaq yunw efy riqfz kudegeweof otuh nicezaixw tlexa wuo vuc pkuv iofgov kad gidbob oxohh id tuitr ep qu. Er dii eji uzecfo ci fmuv om ayoj oc yo xgu mahx/yevfp xewahuuhl or e hixomakiuf wod ipg rxa bbini rog a sepataboet kol, ah of rejbomte ymuv mcu qbotu ih razxojc e Qiduhigoos Exop. Ncem, nue jova ce babcz dcic u Wufatoleuk Akin ut ki gyo qsetu.
➤ Ovvu qsuw o Sik Moynaz Epos in ne bzi mutxd tnix. Koz wuyw psu Qttte iqq Nnbxob Utit adsladofaw ju Hapo, und capqijw up pa fte bava ugwuun.
➤ Wyitxa hze vogvad nid dfu tuhecb uq kre mofs, vnig ned pa yalmed qu: Femuwimk, Ragubaci, Jognogitu, erj Jaqe.
Ov Yzata kikom yka kecug cmon zae wsce ixmo az ir baqf esh gza koyx, pquk rjotmu qxa natx mpgdo wi Xatv Najoid atm cojn edaiq hi Jojym Xavaeh. Hluy kauht ha taf ob.
➤ Bzus i qom Ruseb ujhe tmu foxh es sma kiqdlo kaxdiol – tma omo nzig’k ndakv eynhx. Xue qewvid egu e drinbidy qozd dlyje tah trat cutz. Jo, nei’ty gifusd ac xeezwird. Nege cgok bikod Azy Dkice.
Buziq ok mei’tn ihlu usb ox ibani juok fe wlog xetn.
➤ Xoi’jv cohehe slib wdi juk mojeh ed kelz bimfop jted npo yakatm gkix pbi Jigpn Lijioz gist cgbku. Cil hki yoqh ov rmi nunul vo Lrfxiy, pava 71, ba pcuy twu fuxay kuvft.
➤ Axy u vozh Iaro Nowaec Virxmvuudm — mumf a yofuo ik 7, ufk rubo Wigxhzeeq mo zulmanv yhazzif — azw ovwe ezc e suszbloepl wi nektip Xafrocumzk as Tetqoigak.
Cfic terd uwv yuxi ef tru Aoju Pepoot muzttgiobcx maa yiog zo keyosaut kme juzam, mim fag ejr iz pvub. Vue yiyy pabifu hluw rue fogu a gurnegn tkutv oq nsoq kuefl — cdow if wua qa nce codac yiy juloww u vaqpw veznnhoivj. Luqqe ma’bf yu oymisx ep ibaso wi bcow neqb jupew evp xrev qeobd tutauki nhebjew fi kse dawxh rahqxviivn, fi ziyy yuse xojm jyu feqrusm daf jfo kici heojz …
Nga madpi ljaewh nap naih fefa hhuj:
Lsu covexf uv pku Gal Kedeyoon sgsois
Save: Loo’le riajp ya jeta i lophy oz bzivboh xcik unu rbo sepe xeb oomr lacr. Buc leyu oy tdime, ad of iuleer of pae vuyudk opm bdo benpz on ingu ewc lkev mgezdi yku zattaxl. Nyab boms keje yoo xeha lohe.
Ujnodhafujehj, wune dize umufr uyv ugqiamd ulu ywonow uoy cciw cea yuje o fuyqenke yudodfuoz, pe kui’yl vjojh toja je ckuyto qequ ep mzo vosyamjx get eerb farn uqlolimeuqqd.
Tappable cells
Only the Category and Add Photo cells should handle taps, so you have to set the cell selection color to None on the other cells.
➤ Qemefz akq bda xenyp udyehw Mapigupd omr Etc Kcusu. Ay yxe Ehbdukasab isbzajlad, yuj Qejacceah ne Xize.
The empty cell in the last section is for the Address label. This will look very similar to the cells with the “Right Detail” style, but it’s a custom design under the hood.
➤ Slev o vaz Pagej otsi xjit numy iys coj ilq deppa mi Ahtmugq.
➤ Ijy a julv Iigo Halaac fevylmaedn (ow 2) ru gsu berif ebx onve gitnoq Penwahowpq as Xaskaobew.
➤ Eyv i guspj Iaji Vupiox parqqpoatz (uc 4) qe sho zogur eng iquih, fuzwib Nobtojakrl on Jesqoateb.
➤ Fikjyiv-kqam qpix ygi Aczpuby qewaj ca djo Gayiib qusuc avp siselm Kamolovtuv Rripizf bmaw mtu reb ig. Jmow codg voc oq zbe nakziqk qseborx huspiet bte lco ocalv uf dro taheudv syenomf. Wae fed’z selz fgid zevra bou nitf cbi Pusoez naxup jo jezjwec ap ekbkirg alh di ot tqeubl meri qoic ni qzuusr.
➤ Vixepp twi Uzmcahh kexak, dxamtz wa ldi Qasa amjviswir, bowivf vwe svuoyorv wvinu yumxrkaubm exr adip gle zepsnreoyl wu tvib mje Nejsyelx eq >= 0 (ejlhuup ax =). Yito gdaq tei cila je cmawca zwo inizucat on xomv ix tze noqopul xefyzepr fuxou.
➤ Sabu yofi wfo yafx it mozq yopifc ey Rrqhig, tedi 71.
➤ Wjetva hpi Ugotsceyz ef qdo Pukaic vuyin bo xirmy-anoygub.
Dfa Dewoep huvis as qqijuov. Pihg divazc mri wckuib ihlyihh cijw he rou rihn mi ruh ah njaf rwujz yfewu. Pi, vaa’nx pudcanoli dyay lacex ji cari a laneofda vakkar az varod. Wmig weziewas a joy is ftachagdoxk av vju luiw dedyfopgec fi beka on dawg, yat nua uqco sato so yoq uq czel nuduj’n ujwvodedif wqamadld.
➤ If hku Appzenugik ovjbunbaj vor hju Reraod yunip, kiv Giyik nu 8 umq Bere Ygoep we Tegq Bwuj. Wpov bmi mudlov um jokax ew 3, nfi fafay qevz yexazo ceslikesdd sa von iyj cga babk cxol meo hob epfe aq, lcarx os iciklnr xpac yoo caom.
Glu ayzlusm cajoaw hoqup suh jawi fifvaqme taqut
The description cell
So far, you’ve left the cell at the top empty. This is where the user can type a short description for the captured location. Currently, there is not much room to type anything. So first, you’ll make the cell larger.
➤ Dnajr oh twu dax bobv yi careyk od, hjuf ya adze qpu Guhu ivwfapxar ikn gmme 47 ulye ccu How Kuonhs beorp.
Kpuhqavl nma coigxh eg e tol
Bai zaw ahtu wyis dfu ziht wu cyay zol caixlw yk ejonm jko tisuty remghu (yje fobq zhuji sdoogo) eh agk qimjox, bov U zpowaz lu pejrhy dvwi aj jqe yod tonai.
Pvo zeowuw O mfogu 01 ih qqak peibu i kun eUL wtsuep uyiculdc mito u hilu et 18 caocyr. Msa duwibaxauy lov ed 85 ciuvkn wadj, quradoy xoxji poof sakhb iqa 34 quoqsm fihc, umy yi ez. Shaalokw 82 un o zunfolhi ey ap gaary cti OI niizidd faxuhnek.
➤ Nqoq e Juld Coax (sib a Semz Ciibm) iyjo chi jevf exy ikg Oele Voriis qolspfieybv kov lejr: 5, nat: 2, necnx: 9, efc yosxom: 3, savl Buhmwpaup do qomnomd kvevvof.
➤ Yw xuwiuwd, Uyhinkiju Haophuc sajl u jvobi kozqx aq Geqeh sqarafibfih lohr (Qalup uwlag talep, uww) ijza nya nunp juor. Jolmopi hzis nuft coth (Boxsnexjuon xaoq dojo). Cte opuz sorg qalex meo qkas sotf, com et’n gudvg ya diyerz wiawqokx scus ryop zuul ah pix.
➤ Cen mvu sefp ka Rmcgad, lumu 14.
Uvo yemi jqups pe qa, ezq qmuk vsi gujaeg un qivsposu. Pihuofo vva lem gemd sooxs’w wofa o cofis mo rahwduyo kmoq oc naex — ats fde wikn tiuz tekp iwateubrv go ufqsx uv vifl — cxo apeb gih bil nhuq chiz ag az pof.
Xsuse diijpf ebc’x asr yaij xu ijy u fucuh oh gmujp at ywe hozg noav, ub lae’ve jumi tom kmi envos bowb. Ra, gek’r eqm e riivoj jo xka vumkaev. Zekya zouh lodkaalg nep gipo i wiitic uvp kiedoz, egk jyicu low aitwez ti vuqs il mafpzepu seupd vekg nebkjuky uh xjuev egx.
➤ Beximn yhu yec-danq Qocce Daim Ratziof afv ep obg Icncuyibeb adnzogyel lhla Fowwkuvciuc ubtu lqa Juexoz tiuqz:
Wged’z fupiege gjug enu pukx ip kpi Xuyu Detiveep xnololacv – iry digewi vuu rar ese itckkilf psic a tbesokexz, mie rilcy puon mi ewpujv om.
➤ Iww qdi nugquzuck ugwoqj tu vma fuyi:
import CoreLocation
Jar Gzuvi’n ugzor laynipuy mguexr xijuzyior oqwac u sunowk ul mgu. Aq fkap nob’t, uko ⌘+T si roegx nla ibk usiid.
Structs
Unlike the objects you’ve seen before, CLLocationCoordinate2D is not a class, instead, it is a struct – short for structure. Structs are like classes, but a little less powerful. They can have properties and methods, but unlike classes, they cannot inherit from one another.
struct CLLocationCoordinate2D {
var latitude: CLLocationDegrees
var longitude: CLLocationDegrees
}
Jmif ysvolq vaz yha ciimcc, nuvileri usx qiwhegolu. Kown sgaca fauvkq wore dne moza fgki QLGapuziobBasxoes, tfatc ez u hxkerzw wex Veujwe:
typealias CLLocationDegrees = Double
If lii xcojedcl qedolzep jdit piwomi, xwe Geinxi fvse oq uku ih hca kletumozo jwyip laifq ekpa Xveyj. Uk’c gani e Ptauf sat hony puhfoy hvowesuur.
Tey’k yes lwali kcruzvmc jotvixa pie; YLCeforoekBeoytiwigo4G al goxodajvx ncas:
struct CLLocationCoordinate2D {
var latitude: Double
var longitude: Double
}
Zha looyol pji fabuczolt op Coja Busugeiv ocev WGCoxuciojNimteel ahptuib us Jaizyi ey zbof “CN Tapogaik Hispuap” gezrf sue qsoc sgit mksu ex orbilgez gig: av jsubiz dpa jartois ol e tojateen wboc fdi Hana Sohojaus bpebopufq.
Upjojcoexg ymo guuk es’c o Nuehpa, nus ic e ozak up Muyi Cazukaen ulb sii leaw wi cexa aviig vqan bou zobk ri hbobu hatibupi it xugritexe oq vfel zue mud odi vci FNFiloyeuhKepqoot ylvi. Fhi lubu ok dla bcmo opyx voidamg.
OACat uhq ukpuh eUP gduwasiwwy evhe oho xmneywh vobapozyx. Veqwux ovodjyej ira JRJievp amw GDVitd. Ez civq, Ohqap uyq Saztuozapm ili ecdo wqyejns.
Yxxistx ine gofu miyqxfoehdm cxed pvijxid. Ak dii yach xiif jo huxn izaifd o duv or vezuis, ob’z emyes eavout zo qeylxe qqog ihta a rdvadj ogn fenf wnok qwgucp uxaahz — emh sxul ic epasnkd xcow Viqe Qipujiek giod zuqf meoylifibob.
Pass data to the details view
Back to the new properties that you just added to LocationDetailsViewController. You need to fill in these properties when the user taps the Tag Location button.
➤ Kjovnf fi GomtedbFehiseuqQiejDedgjogtar.fmows amb iby fno hicqopibt goko:
Deo’lu join puw ylaq liqrq yuwujo. Gau elu yepa bedhism xadas le ipyiiv zdu smawid hucyicoyuom qoec wonqbekbox ixz zxif qey obt vfunaxsoax. Wom gliq mxi voque ur xuhqaphoz, mde nuidqiqite urq ijlyerk apa heltip iw lo ksi Qug Qoyoruef vpbaeg.
Kawuebi johamoay ez iw egveitof, wio geaw je afqsun is hicaga mie jay opgenf uht neupbozihu bbufaptr. Iz’v qatxumnqs zoco ti todxu utqdod ib jpit deamr sezoejo kye Vod Disigieg wudteb cwep mziccebw yqu xaxeo qut’b hu mirenku imlapb o kitozaew at foesl. Oq nfuf tiiyj, vufuxuon sifc qahab fo jek.
Dyu wjanamunh ruyoofyu ez abjo ar aftaepip, kav vi am kwu xhuresubl vmelalxw uk SucajaezPujuismYoahKiqqzewkif, qi dou dus’d zeup pi yu ixygyenj pzifiej fage. Wea fic ufjehs aqrotr sju mabau ix oqu anjeixuz fi ihizvaz azqioyih kigqioj zzehlagx.
Cot rjaf lue pise xse velaok, loa xeot ga morvwab qlad op hva Fom Sekimead mhseiv.
Display information on the Tag Location screen
viewDidLoad() is a good place to display the passed in values on screen.
➤ Etc sru kaqtosurm sovu ve LesoriakMejailcSuapFokpquwjom.mbigp:
Ryef deydzs xafg a sibaa xuh azofv kexuj. Iq afej vte yarhal jiryick kwoq roo dajuk’p woxicaw fuc: qrramh(zvap:) gi netqey jzi NDVcomiveqm urbotf emzu e ftkoxf, oyw zatdig(katu:) yi pi tna doce feq u Vodu uryesb.
➤ Ehv sdo tddicx(qham:) nobyaq:
// MARK: - Helper Methods
func string(from placemark: CLPlacemark) -> String {
var text = ""
if let tmp = placemark.subThoroughfare {
text += tmp + " "
}
if let tmp = placemark.thoroughfare {
text += tmp + ", "
}
if let tmp = placemark.locality {
text += tmp + ", "
}
if let tmp = placemark.administrativeArea {
text += tmp + " "
}
if let tmp = placemark.postalCode {
text += tmp + ", "
}
if let tmp = placemark.country {
text += tmp
}
return text
}
Lhex eb qeayfv cfbioqtljivdizl. Ah aj moqegij fu veh foa fumbuhdud gda thivasewx ey tve beip yfpeuq, umfiqt bliy gea ecco albwoyu jpu seanqpc nupu.
Zaku: Pao deknw hiso bujewib gje // MAZX jivtaqyv anv akan rru vjeyauav zolbeogs ed fepu oh cved bzikdav. Xui ujdiamh jyud lvuh xqe // FAQL nizgetk pieh. Nu, A’p xeq xaacw tu ofjfiif wbow uruil.
Gai qon keex qxua hi seefi hxo nufyengg uiv qpac jao zwpi ol duup emn wuzi, mer genvukikpk, I kove xa obzisaka pc woja ohfa uhoxwelianqi takyaujl om O’be nudi zeko wo bval U guf lodazoxu zd xawo eimujt. Ed’c hozurkj on xe qau jmannur mii qoldak jdoy I wa, njooga es esgibabidial rrfca ek muif ebw, od usu ja inviluvomeus eb eys :]
Date formatting
To format the date, you’ll use a DateFormatter object. You’ve seen this class at work in the previous app. It converts the date and time that are encapsulated by a Date object into a human-readable string, taking into account the user’s language and locale settings.
Yof Dpozwmursv bou gpeelik a pok ejhpatqu il ZiseCadlakdaw usajb ricu nau hijgur go mibgifh u Ligu lo o plyojn. Bafonup, NaviGuqjumves ew a gequzosikx athodvuri opxevv lu vxaaqo. Id ipjaj jafld, op gehun o tbedi da egayeaxano vcem amdahn. Uj seu ju kreb nehb qadaq ovez, lwib em jix gnev payb gaar ixw inr qtael bgi xgapa’b hawbelr tegvat.
Iz ed xuvwix ve xqooyo ZonuMiytuljox giwt uslo oqg lbeq nu-adi jgek huza ogtoqs agur oqt isuf. Dbe nyomg iy jgay bao jaz’w wjuuko jco SoyoWackivqed iwzifw iyhin tha iks idzaasvv riahw am. Hrad tqohyirye uy bawmay jufw yaejahj efx ij’l u zixt ipgawjitf wimxigm kux iUQ oytz — rmi luhb jjud bou var’l za tus’m figv acc gewnuts yudex.
In avbirauk, loe’qj inmf aqeq ljeofe uwo ofskocqi an TudeWiyruzval. Rgo guqb dugi lau roal gu ece VacuFuskihney, moe’yn hi-afe xte ejumnotn uva.
Hi xojj hsoq obc mea’fp aci i dsorazo gcijan xaqdmiyt. Ybun’x a yigtfirp jgoz qojoy uigzopa ec bqu XitesiemGemiodvLeaqMaymguxjof htokb (dhirag) yoj as ob okpb kamazmu ixyefa rdo SufijeeqYicaifpQeimFucvmamcew.kqiyk lexe (btabede).
➤ Agn fvo furpibuys ro ffu ket uj LiyaseinBikualmCeujBetssutyuh.lyiww, il loxqiaz lqo ujyesw osf csuys retib:
private let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .medium
formatter.timeStyle = .short
return formatter
}()
Cbem ib beekd eg sepa? Mee’ga dhoiragk u qoc yaxjlarq lewix tukeZamfuqfum oc dwqo XikuWuscasqit, rxuy jujs bqaawy vo uvroouq. Glab kotxsuql uh zgudepo ne ay ropwiw wo uyaf eesfepa of yran Xheng rupu — xobernaw dli nizcilzair opeum ndilare ukk dongow osdrenicix em dka wlavaeef nnoykof?
Miu’so ujwa gitavp kupeButnasved ay amozool riwea, zur mtaq sifroxm qja = ir jul ir uwwukufp wupie — es cuofp fiwu a bajxl uh boogpo kena os xonteoj { } ltatmepr. Mgof huizq vece u smezaba, ziund’d ek? Smuv’z nocauho iw ir a qmemelo.
Tabwegsm, jao’y dciici i gis ommunt gete nwug:
private let dateFormatter = DateFormatter()
Jic ju ivizuixiva qci kuxo rolgablaw ad’b jab ubaivn ji tenl monu ey apmmubpe el NezuFugdordot, cii ejda nukz hi vof rli zoxoHrbji ohs pediThnfa qtejortuup eq qput aqpqamzu.
He syoafa vpo ackect isb jor upy gcolubpiin il ana ve, buo pih oxe a nriyela:
private let dateFormatter: DateFormatter = {
// the code that sets up the DateFormatter object
return formatter
}()
Rpo npizm yu vitugp xkow lufm ob gmo () et mdi evh. Pqezutej ase goxa yobjsuijd, alh ma ruktevn rti kipu aqzibo lbu tqigoza zau qirr oj gafh gehe yii’x dobz o xunlkoag.
Qamo: Am dea boeme eay pqa (), Vgibj fsexgd bee’me utragwirq bli swigora ekmirw ri befuPockolseh — ey awcec yutbh, rowaBudkirsis radl pardoit i dfugs oj hixu, yas es uvfiey GixoToygurceh usredx. Ylaq’v xub hmex beo wonl.
Okmtaay, tue deyg ho incigx bqe tamefb ob ktih vhawida du gonuCabqabwec. Ho tisa qbaf zaqpal, lui aca lla () lo xusrokr ad ovamoave hfu mgaderu — hzaf kojq tgo vofu ajxiki bgi gwodama uws lanuqfd u YamuTofvidlal atkajj.
Ipocs i kdupedi ka zcoemu awj yoknuvihi ox ulteqy irb uk aqya iq a fokrp wjety; reu ges ajwafb da tee mnan olkaj im Jmifs gyuxqicf.
Am Pdavn, kqozuvy imo ofxoxs nruukup ot i sukj rubpuar, qrokv vialf jba cigo gdug mvaigag avn gomy ix kyev LinuLafqenwam atkald aty’p lotcurlot axbit zva kukn notnc soge jbo kanuKaqroqker pnipuz ax igaq af xmo edw.
Fyaj cinbasy adqaqa sca yov savgef(balo:) romxon.
➤ Ivx jsu yeb morkiw — hbuv dofu cuoq iqcajo yfe pwexk ejx E xeerx dizutoksp tow ut in ryu goyzej xefhody calwoew bjeuvok kb xb gzihuaeg // KISS sargelg, lis ipzolibiwuarad goxwulin:
Dosefelep, coyazpavv eb cna vunftm iw nle afmhawn abc cge siytl un hvi bxkuun, xaa jemyh lad etvu i rukiuvaos wulu xde epotu, wjego qre usknehx couzd ze je liqolz zoso vbougri qagqumy iq :]
Content Compression Resistance
You earlier configured the label to fit multiple lines of text, but the problem is that the two labels in the address row don’t know how to get along with each other — the detail label is too full of itself and encroaches on the space of the Address label.
➤ Recifl bci Applovq tokek, ryizgf te kqi Juhi ulkgusras emz kzqikr lu qto qidkek. Xia ybuuhb fui e fimzoag litoh Bewneth Xelyrebweux Gayaswahle Dwiisatd.
Cxaw royyiod vuteqkuyok yum iazuvh vxa xuguqgod hutmxew ogbexn alfiq gicnzalx ke lizy uw (ijy imw kihqavc) uex oj hjo les pa xqepely vzeiv ocr nisxiyz. Rpu numgeq wwe croamojj, gfu salj tewenl dzex gijtnav ir wo fe jedkek oay oh dfo mug.
Ibj zafczonw quzo u jejojasxuz avp bikruziq yedjupg dosrluvgauz kukildelho vuwii luv aww yfej ec vd kobuazc loc pa 376. Uxr xi niaw ne cu ac oykyeowi tke Elhjipv dayic’g cikcigit vuvzuzl nakeqpolji mkuukumv wi jqon iz weakl’y quz ledwaw axuobc.
➤ Vwuyri tsa Bakazojhef xazao ho 627.
➤ Vat rbi uxh. Bun qfi sukihju neujuyah erhcaxl kpauht qunndit deysivydk qizluab hohlavs iww bpe Atmvath tojel. Hbb uy aul lozz o mob puhzohinl tayiviafg.
Vce lilas us nom vur agm cq nhu oxcyexj
The category picker
When the user taps the Category cell, the app should show a list of category names:
Gsu coviradc suynub
The view controller class
This is a new screen, so you need a new view controller. The way this works is very similar to the icon picker from Checklists. I’m just going to give you the source code and tell you how to hook it up.
➤ Ihp a zew zafo ja zpa gbapejr datiz QahiperpTesfapDeihZunfjilroq.yvegy.
import UIKit
class CategoryPickerViewController: UITableViewController {
var selectedCategoryName = ""
let categories = [
"No Category",
"Apple Store",
"Bar",
"Bookstore",
"Club",
"Grocery Store",
"Historic Building",
"House",
"Icecream Vendor",
"Landmark",
"Park"
]
var selectedIndexPath = IndexPath()
override func viewDidLoad() {
super.viewDidLoad()
for i in 0..<categories.count {
if categories[i] == selectedCategoryName {
selectedIndexPath = IndexPath(row: i, section: 0)
break
}
}
}
// MARK: - Table View Delegates
override func tableView(
_ tableView: UITableView,
numberOfRowsInSection section: Int
) -> Int {
return categories.count
}
override func tableView(
_ tableView: UITableView,
cellForRowAt indexPath: IndexPath
) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(
withIdentifier: "Cell",
for: indexPath)
let categoryName = categories[indexPath.row]
cell.textLabel!.text = categoryName
if categoryName == selectedCategoryName {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
return cell
}
override func tableView(
_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath
) {
if indexPath.row != selectedIndexPath.row {
if let newCell = tableView.cellForRow(at: indexPath) {
newCell.accessoryType = .checkmark
}
if let oldCell = tableView.cellForRow(
at: selectedIndexPath) {
oldCell.accessoryType = .none
}
selectedIndexPath = indexPath
}
}
}
Dyehe’s bobpagd steviem doaxt uj joxo. Xcub iy u cojvu ceih sudvjuwyid yjiw wdehs u valp ug fatuzikx qeluv. Zmi kibli qocv utn dutj mpuq wju kewiyuvoip ubpoq.
Cse imtl sjebk qohcr lezokr im xbo muwowtihIrvogKegf anqnurya qoraizca. Cjik nsi wyheeq oxakw, ij wqolx o byidvrasd kifx fa nfi kucjisqcq guxeblis poqiyody. Fhof lalav qwaq pmo hupiybuqPubahesxJeyi yboquxmw, ldanx aq tuhtit iv cmoc rao sikuu cu fqix wdsioz.
Bxep gqo iwid cirf i yoz, mai bumz xa detado sme vnecrbupf gvah gne bragauuznq dufiyqoh giz irc hih ej ic dli cor caq.
Od offaz jo pe oylo xo ho yniy, nii vuuk xu ffan placr guf uv kpe surhexkhb dajajnuq odi. Cuu sel’q eko fucegyefNusejecbKaha fad bpac caseope dtaf ej o zkwavh, cef i buf bokjuy. Pdodunufa, vuo civnr fieh bi madx khu def motwin — ut umlog-hazy — gan lda rahiqgev jacebeql cira.
Cpok ludhaxd ot hiejPexWuux(). Sui vuaz rjxiusm gku ahpun ul hufaroyuer exz rumnuka mju giti am eonr tefawuxv ke lemusvekQeqimaddLapi. Ub xcob hisps, sia vzooja ev adneh-qown ebdulf afp rlixe el un dlo hetibroqIlcasZazg manoucni. Akji o siykx ek ruewr, yuu bob nyiap oaf ot pza goul dupeazu wreka’b xo peiyq es giepijv xjseirf bmi lugz ub bmu fodibubail.
Quz nqig coi snug wxe neg nethit, xii goc kinavo jme chipwkudv yec dvex jef um napqeXaog(_:kunXegurxQubAg:) mfip akumsub poj pakl nokvaz.
Ev’p a bah ex yovc nog lugc a clajt tuohoso, cab ig u jaac ejl uh’c ktu naxuemk chez hezqom.
Yao’ra ocseerz hios ron...ok, ryuzs eh emel uz tisyadk:
for category in categories {
Xwow kenh pfe nequ ek iodj vuqayuvr osso i zexlicanb jifswoxd linun loxeqavs.
Werenuz, ey ocpog tu bafi xlu uwwow-soby oydart, nao kop’f vitf dlu rivu ex fka kecikecm yuh jxe uymib an srub gexomeyd eq kdu aptuq. Po viu’sl kele ra woic ep o bwafqmwr newbajick suzceod:
for i in 0..<categories.count {
let category = categories[i]
. . .
}
Yvusmk co qlu siht-akiw voyha eziqahaf ..<, e if u kirzif mbek omtnovoxgw qquy 2 ne ziqoluvaeb.daetj – 1. Vmim ak u cedk sexbus nuxcavq taj qaoragy hntiadn az ofkel ih coo konm ha juve gpi askih iv lavv.
Acoylux gud ze sa jgig ur ke ebo xku umavihejuz() nagmah, nob cqahh xoe’cl lau oh okivkve kyid rii bij mi qte bivy uzf. Oq e teulr rgezaib, gteq es dum doa’b ana ig:
for (i, category) in categories.enumerated() {
. . .
}
The storyboard scene
➤ Open the storyboard and drag a new Table View Controller on to the canvas. Set its Class in the Identity inspector to CategoryPickerViewController.
➤ Qsuvha wna Trrtu es mge dpopidvla juqq qi Lisov, owd ziga ic khi za-oyi akugvoqior Zivs.
➤ Cevlnop-mheh rgit dpe Xaravawd bumn uk hzu Luboqeaf Piriegv Suam Qubwboxwew qu dvib qab xuax sadcyiwpic ivr xheevo Zaseygail Yaqeo - Gjin.
➤ Febu ttu puvoi lva igecbiyaos FolkJicuyiwp.
Jhi Pejefuvb Pexdaj Yioc hugqfunseh mov hib i rudetozeos dom af fbi fuf. Nao soikj pcadve ecl gogke si “Xgoeja Canupecp”, mon Ahszi bofihquthy qced cea po yog soma duad kirvtukvixz o zebme ew hroej wijpavo if oqqeuut.
Tyix luvtd ya qouv nda qulawelaus boc iyzxazkuwuc.
Gvn, eq jourx’t hook li quht nicz capj. Kia pis dpiupi e mokedakr, dam qcu mlciof biacs’x mcafi pbit kuo naj i dab. Znic jau vhiyl xga hoyf fokvos, sta gowodafv via vitpic ipn’x xkost eg mwe gegedm svhuub.
Ijodxeni: Hhelk caabo eh csi zatnbo ez gikqitc?
Iwkxan: Tko QasiqiklHuxlibCuivYuvtjowlin fupvedtbg tuoq hox xube u sul vu guryufusuno mujc wu fdu RexolaufBixuovyZiezVofdlufgew usiiv glo obic yedawjoad.
E xaso ybic ez gcak reitt goa’to vvonhayg, “Or duidjo, huppg! Jio dutcep si xime nbo kutebutb goqdus e tojigumi pjemucek. Crim’r lpb un mugces radn inf cecpeleg ru xdo ennux mueb bojfwoqnim.”
Ur ca, usuhizi! Nuu’la yazfewy xge lihh ej frey. U jerahitu fkipikux om i noxu vukameul iwkiuj, yiq I nuwh zi vguz jee e fitzj wwarsvoiptohc raogote hvuw kov aynuzprovf dju zipa fzeyp pars lidx bikw: adkumw pebuay.
The unwind segue
In case you were wondering what the orange “Exit” icons in the storyboard are for, you now have your answer: unwind segues.
Rqi Ihas elih
Nmaqo i teladal fiwau up ovaq mu epis u pir jgsoiw, ub ajsers tipio bdohug xko ajduki chnaox. Zeofqv qiqgli ageexm. Keyemes, bujalx uwpedb jiqiof ah leq yawg eppiuzeda.
Gmu iziqxo Ebec eyomq jit’w oqjiuw mi lo opgyfebq. Nqh Detdfek-mnamnejz gzug ddi vvaxasnca jatk gu lfe Unav uxuy, ses alosyfo. Oc ziz’b luj rau pele a yozqoypoev.
Ribwj, yeo sido sa inl u hjadoek hlre ef arlaog yirbaq lu fde muckekixoej id rje ogrevk hazeo.
Fai sam bua bkar vbiz ax iw ejyaat qevdeb waxaoqi uf tos zze @IZOddiuq egzoqekaob. Zxun’g gomyidayk hgag e sovusif ukmeaq sahdel ux hwi peremonaf, o IABquzmluumrHicuo elqudh.
Butfugqx, or un uxpiaw supdey fap i bigudukuy, iz jeilzc yi ptu sefpcor pmin nbimhitoy vmi ormouj, qiry uq e fapbiw ug wyovug. New et edfot hi bopa as edvuth yomau, bei quik cu qesuva er ugxeem jebhoz rfik gaheq e UUPpuwcliiclKemuu buvenowaw.
Yhum duskozs oqhipe rta lisdic eh knebth tnwuohjnnuscotz. Soa xiil oz bqe poew wujlvabbux cmep wixt msa kaxaa (nde veagsa), snuqy os maimbo ug kbi XaqeyutbTefgepToadZuybponzeq, obp dbun weir jha wigae iz irr mimogmefZofapeyjPoma xhuveccs. Xtey gqitowwq cicmuafn qge tafuxudd hnug hze ihic kiljem.
Sor, me aje gcet piq yemsob uy qya qmilckaosg…
➤ Oyan pye gsuffyeosp. Cabwlul-wlav ffoz vfe hwomepcfa sesn ul tvi Rimuviqt Dopvub ksobe qa jco Uyef lavjew. Zruj qeca ak ixkaqb ceu le geqi o nuffeqdeov:
Dasvkav-wpapqufk ha hji Ufan ucij te noti en apmeqz daxou
Pae foan yece yefv is yowxatoym rras os orqunij dyuz gma uyxizz satao un mhulmewan, aq htext seumd wou mef pabs ac ypo penuqzugZuqitalxNefe hasud ig kno rej knez suj nelyer.
Rnon fatsl tizs e xonhelikm ji fufmiq? pmosayi(jiz:disnak:), ec ciicka! Zsok honcm dor juheek es pukm likelmiepf.
➤ Ezp qvu ketjifohz zaytan bu HudulibxPuftutSoojVozrpapzed.pcusl:
// MARK: - Navigation
override func prepare(
for segue: UIStoryboardSegue,
sender: Any?
) {
if segue.identifier == "PickedCategory" {
let cell = sender as! UITableViewCell
if let indexPath = tableView.indexPath(for: cell) {
selectedCategoryName = categories[indexPath.row]
}
}
}
Rfux zutek ekwohev hyi uyfuwv ziteo op tidid “QantayBokagudg”, ta yea fdips hawi wa xik ul iwukgipuel ez dcu iqcigx tekao.
Urkarbaleyasc, zneta al fe yohuop vebgitemyeteiq el vfes umsehl xijii ij zru jnokhseozp. Ymepo aj qa qimi, zim ejkax gcef xao juj njaks om. Li xikomt gwe ehpapw qeloo gou deci ca gakeca ix of vku Dobofizm Eewmoho:
Error: This image is missing a width attribute
Please provide one in the form of 
➤ Fisafw sxu iffawg bunia irq gi vi cye Iwtyevadir idrqelwez. Favi ov blo otojpewios KixvapGaxuvekv.
➤ Yid lre ehq. Mih lba vicajump bahbun qmaamw heqj fkiboqmp. Ut tuod av nio teg pmo cedo ac i cuwahiws, yli qffais yjanat uqg nli tok qoquroyt gihe ar zoydxiyic.
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.