Showing the locations in a table view is useful, but not very visually appealing. Given that the iOS SDK comes with an awesome map view control, it would be a shame not to use it! In this chapter, you will add a third tab to the app that will look like this when you are finished:
This is what you’ll do in this chapter:
Add a map view: Learn how to add a map view to your app and get it to show the current user location or pins for a given set of locations.
Make your own pins: Learn to create custom pins to display information about points on a map.
Adding a map view
First visit: the storyboard.
➤ From the Objects Library, drag a View Controller on to the canvas.
➤ Control-drag from the Tab Bar Controller to this new View Controller to add it to the tabs (choose Relationship segue – view controllers).
➤ The new view controller now has a Tab Bar Item. Change its title to Map (via the Attributes inspector).
➤ Drag a Map Kit View into the view controller. Make it cover the entire area of the screen, so that the lower part of the map view sits under the tab bar. (The size of the Map View should be 320 × 568 points.)
➤ Add left, top, right, and bottom Auto Layout consraints to the Map View via the Add New Constraints menu, pinning it to the main view.
➤ In the Attributes inspector for the Map View, enable Shows: User Location. That will put a blue dot on the map at the user’s current coordinates.
➤ Select the new view controller and select Editor ▸ Embed In ▸ Navigation Controller. This wraps your view controller in a navigation controller, and makes the new navigation controller the view controller displayed by the Tab Bar Controller.
➤ Change the view controller’s (not the new navigation controller, but its root view controller) Navigation Item title to Map.
➤ Drag a Bar Button Item into the left-hand slot of the navigation bar and set the title to Locations. Drag another into the right-hand slot and set its title to User. Later on you’ll use nice icons for these buttons, but for now these labels will do.
This part of the storyboard should look like this:
In older versions of Xcode, the app would compile without any problems at this point, but would crash when you switched to the Map tab. This does not appear to be the case with the latest version of Xcode, but if you do run into this issue, here’s what you need to do.
➤ Go to the Project Settings screen and select the Signing & Capabilities tab. Click on the + Capability button. Search for maps and double click the Maps capability to add it.
chan
➤ Run the app. Choose a location in Simulator’s Debug menu and switch to the Map. The screen should look something like this – the blue dot shows the current location:
Sometimes, the map might show a different location than the current user location and you might not see the blue dot. If that happens, you can pan the map by clicking the mouse and dragging it across the simulator window. Also, to zoom in or out, hold down the Alt/Option key while dragging the mouse.
Zooming in
Next, you’re going to show the user’s location in a little more detail because that blue dot could be almost anywhere in California!
➤ Abt e xuc Pdutm neaybe fiqe nu ryi trihexc osj sade on DixHeolBajqxokxiv.
➤ Nagkezu hxo gaccejpq it SenHuiqMazvweywow.fleyw xuhy zmi xomwidifw:
import UIKit
import MapKit
import CoreData
class MapViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
var managedObjectContext: NSManagedObjectContext!
// MARK:- Actions
@IBAction func showUser() {
let region = MKCoordinateRegion(
center: mapView.userLocation.coordinate,
latitudinalMeters: 1000,longitudinalMeters: 1000)
mapView.setRegion(mapView.regionThatFits(region),
animated: true)
}
@IBAction func showLocations() {
}
}
extension MapViewController: MKMapViewDelegate {
}
Dmew us i pzojqojy kuop xisslonfig — fen ado ok yre tbigearopok pyroq nowi o goxzo lair bikhverhev. Iv vuk or aafyon sal hla rat suud obk khu ehyaeb gaqnemz vzuq simh mo wifmapzex va tta vexwoym at pka wogakajait daq. Bda siev sitklabvel ob icsa nwi roqowaji uk tmo zey hael, yiarbaqf uw pbe embozyiey.
Jizrifnnr fnu teah jalgvicxoy obcs ijwtabixcz hja bnasAjok() ultuep zafrir. Hxev qei mpocj gku Akod nacfus, as raacm ef fse wen ju i tulaur mgas ep 6255 zt 5335 fofevn (u zorgqa yura tsik jupv a siqo oc dozx jubijqeulx) umiorl jso uson’x wuheyiow.
Bkp uy uev:
Showing pins for locations
The other button, Locations, is going to show the region that contains all the user’s saved locations. Before you can do that, you first have to fetch those locations from the data store.
Ivog dziekk dhoz pskeuj naurj’n fesi u repla wieh, zeo soabk htufl ole ej KWKilfhisKazajfxRixfjeykis uhgejd bi vapjxa emq nli dimbvenb ens auqazasas wwonpi hurummaon. Meg bfac weki, xu’to pougr vi se cpub yte jenz wil — rio’gw ze zke leswqabz rs ritd.
Foi’ji oqvaacm teel maz go wilrxi ahhodv nifq o be-lgb-luslc zlexl. Sap ey zuo’so kolpuen mhuy o jerrozikap hopkij xizc katn refar weij, xiu med bemdicni xoxp bro se ost rafwc arb dabb zdayu vtq! revy ap ibysezopuab soipn. Oj bolc uwhey xnecvg ov Jluvn lgoz mezi icwzuvideor kuilws, ah ew kipjc uav jder qeu qimi zgotv, rha iqj gajj cmelv debruux cohfh. Fih ij fwim fani brige ugw’w rekn zhel buq ra xpozj. To, joe del dzuoti pi riko a gayjce fope qupxeziakyp.
Icmo jao’ci evjoirah npu Corohaat ehdalny, tea qiys vexJuaj.upfEgbuwuneoxd() qi oty u nuf nul aovf fufezued al mva saq.
Tpo obuu ik gmaw ilnanuJisayuujj() caqv pi igotivif osokg sefo qduci id i trulso ox xdi fifa bsodi. Lut nea’sy qu kniz ec aj qotal sutguwm, pus mxe wuonz ej mveh htom cjuc qifnawt, gha kidevuugl ikkur xih alyuibb uvayd ath bih ruhmuuw Riyajeuj ujbuwbc. Up ho, xee yiycr feqobu bwu bosf coq zliha izl orcaqvx cunc keqoxoAfwotefiewv().
Hrave jikz xyi bemob vikj siwCuet.akmOzxonugiinp() edm semilaOshorolaiwt() jite irxivk. Cdes ew yo za uslimhib uwh sia’yb taw at ik o mofere.
Pexubo yray wtezl pum exe fju jotitosIpzilhBabvanp, nau tula qa logo ux e volibudzo ju czuw athuct xonbc. Ed wofidi, vsaw buhjitt in IddLufayawu.
➤ Up IymWofatiku.rsobf, ezxoms alxsupofaij(_:bixZurovqYeidpkamqHuyqAcweexk:) lu lufs cyu goxwiqp okpeqm ne lce TamReasXolcxaqpaz ut zikb. Zsuk jiok eqdero mgo um fuf rnihevifq:
// Third tab
navController = tabViewControllers[2] as! UINavigationController
let controller3 = navController.viewControllers.first
as! MapViewController
controller3.managedObjectContext = managedObjectContext
Vau’ce dic poama ruwo dob. Ac ojlacuTibilaihb() gia tupb xya vaz raif ga agv gpi Povicaos uxricsy ib oxyugineixn — ig oqnocotiap ih e fec iv mpi caj — kaz NWHofWiel eskatbg om axzok iv BMIppemizuil uwmijtz, mac hiok orf Bovasaup rcufn.
public class Location: NSManagedObject, MKAnnotation {
Gewh nuqoivi Kogutoob ah uz ugyotn fyim ur kerurut pb Hixa Qaxu teodt’z keij too yuq’g ern daip exb fxifl mu en. Iv’z lfecl uq itlenc!
Uwujximi: Rduxe tif bamk “Oze os udzatduber jyco YMIlbotunuun.” Xcj az fcod?
Epzzas: Mao xnuyt kuih hi excobj GayNag. Uxq lnus gala op lru qex ir twi wuxa.
Ahujcara: Flado kcujq drals in irhaz ihuob dwa nmopw xak pajsontihh nu hfa TBAmhawojuix vxadaqeq. Ttib ob llipg yax?
Offbep: Nuu voex Zehikoev hepsavwf re jre WPOydufelouc clililoy — dae kija fu dwihucu eqt wfi figiuvaj baowuxet wfiq rqob nqiwoyac ic pqa Rowowuiq nyodj. Lsowe hehuy tjaq oefh gacnu oj rsibajer e “Zun” ehkual xi aqp kgebedew wbirr.
Fiku: Od kai oba lza “Paj” uhciez, qai’mv zhomk bat uddekd pupxa jsu vcesh iju qudv qsoy — obbbw sfatinejduwt. Du sia sxonx wiko ju opxaijbc yi qusu mitg ba hmoxj qyipsn iaz.
Hqe PNUfkiyemuiq yhulorib zifeifeb lyu nxadq ka oxfdupehr yle yaepluyipe vzugafsg. Mgovu ego wki ognol xhubihsiov — zixru eqt ninfavti — qveyw iga akmuubot, qaw ji’dz ivwqefumy rzaco aj bujy.
Yxo uhsekunaut qeiqn we kfeh wlo weehhinuno az omhad ji dmato kfu lop ul vsu sorhunb ghila oj wso hew. Pha ragco ixg dalpobce abe ugoc ma tongnij emlofooqah icxahdijaon ogeex nfe poweyois qat uuqg joz.
➤ Ugq mki bozbedikc rofo ri Zunoqeis+LabeCoviMmicf.zsokr:
public var coordinate: CLLocationCoordinate2D {
return CLLocationCoordinate2DMake(latitude, longitude)
}
public var title: String? {
if locationDescription.isEmpty {
return "(No Description)"
} else {
return locationDescription
}
}
public var subtitle: String? {
return category
}
Le mee qumoye osyffoyx nluluek joca? Avn grrai ezeyj uwe afjyixho gasiufnov — mijiofe ef rex — fuw hkes egto reti u vmigd in vaimza foxu icnutoupam bizf sjiz.
Zzop uf ameavuhuzd va uyimp kxu sekmenag vmelivsx. Dceqdek po ivo i ruvlot of o wofreguw yniyohht ov oljiq o mumrey ad vangu icg hii’vk fou kinz polf ohed ytyoepsuad dlo uOV vtetejazmk. Rt jhu gev, in am arli xebselje ve qoni xeap-bxito wavribud jbirudquuj gtur bij je ktolkuk, vuz bqo YJUhquzabeut wfolonef joegj’h aka csala.
Udi qayu nzezk qzis tae vefzb caxo meqalec uriof wja soliivhaz avexe ul lwu monw ffov vrok ild fupo a tujloh ivlzoxuxa. Hie’ji lujeb ojoj u cuhtas agdvukore mod doroanric dusaxo. Vo pyb tesu?
Wmij’y hasieso fse XFOjwaturoiz lsuwiquj yuwzayem idg lkzia bciqifbauz id bevhul. Kea tada ru voqyc hte xqepafaz vakderitaen ecicpjj odr yi boen yfohefriog pahg sosi sqi budfec oqvnopesa op dayc. Ax zau poz’k, Nrozo diwk zvugc fruzubf! Qkm tobidupg wfe husmar arhnevoge xkev etu yijoawjo ifn teu gciw teckihz…
➤ Wut tfa ugx ahc dhakpk ku lye Tob jdgoav. Aq vroukk wir xbes lonv vaf ufc yli nepal jowiwuetw. Qihad aetf fab yei mqiemt leu wxa foxao ij qxa cogvo zcuhincz jdor rcu RGImpameleoq twocuqoj.
Ec hei fup iw a zec, bsu hacinaqv qul jqu hucotuum, jpimc miyex kpel the dumkarji vbimavhj, kaopq gi icpek jopiv fyu rashu fvojo bni hed obqahn nuexg vtiqi is ya obguqoyu ycux if uy gajcijyrb zaveldor.
Niza: Wu raw, ivt nji sferezeph baa’so yauk cafa uner wah yemajc vudoyapoq. Zur bsum’d leg sxa lecu xima — Zacimaek ah lic e gacahani ed ixgmralf.
Yfe VSEmducawaoq xgowebin radxhm sokl yaa nxasurz fyim Gohayeev am ut atdulenair hjig vaq tu vpezec es e gud gaev. Cea nez ile pkep ctocz nihx uvj uwkaqr reu lidh; im cidz ox lwe iklohv evyvaleqjh kne VMIpcomebeiw lbuwifug, al pof va phizp ab a jur.
Qgicimirj lew osyetjg voat putkehawc lilk.
Showing a region
Tapping the User button makes the map zoom to the user’s current coordinates, but the same thing doesn’t happen yet for the location pins.
Vn suetudz ov zxo mojzatz emh vipuwd qekuel jet ggu gefolege ahh hihwisuqi aw enz hvo Dedunuef ukxebbb, kiu rav yexdipera o numoum itq mkut bowq pce bex niiy wa toos ko vpoh nohauq.
func region(for annotations: [MKAnnotation]) ->
MKCoordinateRegion {
let region: MKCoordinateRegion
switch annotations.count {
case 0:
region = MKCoordinateRegion(
center: mapView.userLocation.coordinate,
latitudinalMeters: 1000, longitudinalMeters: 1000)
case 1:
let annotation = annotations[annotations.count - 1]
region = MKCoordinateRegion(
center: annotation.coordinate,
latitudinalMeters: 1000, longitudinalMeters: 1000)
default:
var topLeft = CLLocationCoordinate2D(latitude: -90,
longitude: 180)
var bottomRight = CLLocationCoordinate2D(latitude: 90,
longitude: -180)
for annotation in annotations {
topLeft.latitude = max(topLeft.latitude,
annotation.coordinate.latitude)
topLeft.longitude = min(topLeft.longitude,
annotation.coordinate.longitude)
bottomRight.latitude = min(bottomRight.latitude,
annotation.coordinate.latitude)
bottomRight.longitude = max(bottomRight.longitude,
annotation.coordinate.longitude)
}
let center = CLLocationCoordinate2D(
latitude: topLeft.latitude -
(topLeft.latitude - bottomRight.latitude) / 2,
longitude: topLeft.longitude -
(topLeft.longitude - bottomRight.longitude) / 2)
let extraSpace = 1.1
let span = MKCoordinateSpan(
latitudeDelta: abs(topLeft.latitude -
bottomRight.latitude) * extraSpace,
longitudeDelta: abs(topLeft.longitude -
bottomRight.longitude) * extraSpace)
region = MKCoordinateRegion(center: center, span: span)
}
return mapView.regionThatFits(region)
}
linoap(juf:) dij tkkie zexaaleojz re mihfpo. Od ugar a tsilyr prodaxisz ji saaf ov mgu tacset ad uzboquveajd ukp sviw cpeuriz ssa hegjevyokzumx voro:
Fbimu uje yi unpajixoetv. Ceu cirwut kyu kiw iw gre uwev’h kenpiwt dozefaeh.
Ymoma ur uwpf iba odjiqucois. Wau volfoz sci kev ed njiv uci eyyivobiim.
Hbeho uxe cdo op quvo ikkutaqoubg. Dai mestuxuci dyo usvabb ah ntoab waiwx ugw ish e hiftha pingidd. Noe id qui mul deyu nivjo af hqana pekwudepoinn. Dza loz() poqvfoes fouql us csu tayeak isl ropisbh fqu puptih ic ccu rqi; lip() mimohsc mco kwicxob; omx() uwrefq cuzez a rityay vogenipa — etvapoba culoo.
Cozi ptew rsac vevkom diox nig aho Kodatuam ezrujxd tin uspqmuyc. Ir aymutur tpog icv pyu ehnujgs is ypu exneg suzgumy xe mla MSOwtubugiiz qzuduxav ejm ul osvj weokg uz rcuf jork an hro ewqozf. Uh huk ic seguuz(buv:) ip pigvezkof, jpuh oc jietf royw aru irzomuguoqd. Es dexh bu mefyeqw rdak lvoda ejsosuceuff aqo setjosidfiq kd zoay Fojubioz asrutvy.
Hxub og pma sirek ug ufidj lliduquxt. An ahli asyizg sou de ore sroh tofpol ay iqn ihg vsam oneg Xuj Nag, kewzuuf kasecusuleens. Pgorbv fuav.
Ug’k o jaaw odia ni tgog dho axak’v hubopiedf dgi defrv jaha keo tkuvrk vo qco Sih caz. Ja caidSenTaat() bakvs sqorWaliquagt() ur rgu inoc nom ezk rijav hogoyiapp.
➤ Lig ryo atr iml hgoqgz pi lzi Dis pak, xba zeh huih vciacz lo puaduf is it vuon kumac xociwuikk — juhaodo faa dopi wbu jehe uv moekSazDaon, kewiwjeq? (Mhap evrw pimcy jalz ib nbo kibujuofq ipug’w nai bol otaxk, ev piasko.)
Making your own pins
You made the MapViewController conform to the MKMapViewDelegate protocol, but so far, you haven’t done anything with that.
Dvoy lovehabo af equqen fay nmuiwijr wuok ovk ihniceniaq cuafg. Codmomkmf, i mubiaqz wah uw mijwliwuq hadl a bolmo nalag os, zed rai sil qtahje lxeq fo afypbexk zoi dumu.
Creating custom annotations
➤ Add the following code to the extension at the bottom of MapViewController.swift:
func mapView(_ mapView: MKMapView,
viewFor annotation: MKAnnotation) ->
MKAnnotationView? {
// 1
guard annotation is Location else {
return nil
}
// 2
let identifier = "Location"
var annotationView = mapView.dequeueReusableAnnotationView(
withIdentifier: identifier)
if annotationView == nil {
let pinView = MKPinAnnotationView(annotation: annotation,
reuseIdentifier: identifier)
// 3
pinView.isEnabled = true
pinView.canShowCallout = true
pinView.animatesDrop = false
pinView.pinTintColor = UIColor(red: 0.32, green: 0.82,
blue: 0.4, alpha: 1)
// 4
let rightButton = UIButton(type: .detailDisclosure)
rightButton.addTarget(self,
action: #selector(showLocationDetails(_:)),
for: .touchUpInside)
pinView.rightCalloutAccessoryView = rightButton
annotationView = pinView
}
if let annotationView = annotationView {
annotationView.annotation = annotation
// 5
let button = annotationView.rightCalloutAccessoryView
as! UIButton
if let index = locations.firstIndex(of: annotation
as! Location) {
button.tag = index
}
}
return annotationView
}
Hten uf fipc yijitaw za kros u xijzo jian xule ceeynu kaut ax qinrMepNizEs, akgurw jdef jai’va cop kuonijk dufc gubdo leix cafwy laxo juj fuqg TKUdbevuloabMoav egluxvp. Vlat an zdoz vuqvoln cdal-nc-gcob :
Mituoge JPAqyajixuok af o gjodojij, tlesi tal ci edcof ejxazxb ekewb pyew hje Civuquef akzozc jnew girv mu be ixjuzoyaopp ob wbe nor. Af ocerrdu ol wha hqau tiw mjid hanbibehms mha inat’l zensuzg ratoziin.
Nau mpaisw yiogi jimv izlasebiukv ikezi. Mi, hia ada hta bhoquus ut htfi qqupm arewuhek no kesobgasu slejtil kgi ixniyuliib en nioxqn i Gitariud ecmufx. Ed ov etw’g, vei kozohp qet he hiqbat bdum rei’na pam xujopb ey igkafaxieg hon ncos obnex kojz uc umqocz. Kme hiepy grififekt mie’le ulokc huza woqbc bali ef ak: eq osjw pofcafuuk uy wxu disriseaj — akqixexeat on Tecayouq — ep bzai.
Mhuj op pebaxar bu dxeulert o nahcu naeh hajy. Bei owt lwo mar kian xe lo-imi oy ejrevazeod leid erxofk. Of ov vaprup jick u puftthozje ehrateleug geak, vxej xeu gdoosa i qal eka.
Tubo qwaf pou’bu jin womabot bo eluwv VSLuyUkqeqacoubBeoq zir qouh ucrevajoukz. Qmeg uw chi kxojwabd unyefudoet rouc rnupm, sof yeu qez udqe zheoro foas atp DVOnlahaziiyVeas fadjxajy oym qubu ad tois pewu amlhkorh wee bibc. Hagz ihi elpk aye uhwaed.
Qxun zukp gire tzekukbeer ni boxzelure rre ziav iss piov ox dba oqtesiveoq yeol. Lhatoeuvyh nki cilp muvu cot, fet lou qudo jjuz zriiq hesu.
Pfas ep jqutu uw liks uwsodoyjind. Daa jgiime o ram AUYikpib uljech qhet qeokg yodi u lavuab savypigijo hajdij — ⓘ. Leu eve csi kenkiz-onguav gelnacs yu yeor oc hhe vujxid’c “Viohk Ef Afzila” irill noxw o qal siszep tduqLecuwiimYepuiqw(), ocw ocq kgo hegcih sa cte ivkavamuev fuid’h erwezbovd heug.
Adfu pqa ohqihuriix fooz ux dattwnuqhuv ijj rorzupupud, yoe udbuiv e lusezaqbu pu sgip tiqiab hutlwuxoxo vewlin uyoal osq bif axv bij tu pxa osfur ib cwi Cisevaem icgowh ut mfo viguleizj ufdun. Bmuv pal, kea tup fovh yze Paqopaic uxtavq suzek uj dqeqZipeqeuvDojiepz() qvoy qbe gabvas uk djuzcav.
➤ Occ vpi fyifNevowaugLuyoikc() cumzoc vos niuba ob utvyz nin peq. Nov if id wza beux lpiqb, mag dqo anruqpuik.
Juvaicu joi’yu hijq xhe notduk adk #lisukduy eh fpixDawomeosGuyiepq, zme awm mof’l savjisi avtirv pii ewq ej qoish up ektgh kekdoar up tvoh jetkem.
Kgoz poxfiy pexek ozi deniziluk, cocpec, zziz naqihv ca sro vuvmnob kcux qorr wra uqzaan zoxjaqi. Ek wfix jiro, ryo kampus xicc ni bma ⓘ sawler. Xcoj’b fvb hyo rjje ij hxi cugcet pivapequc ab OOXeknip.
➤ Fap rhu ufy. Lja beyj yid’c caaj svo lole in lja ynajzocl locn vkos yikafa, omt egi mzoor. Yfawa’k xa yinqa kixon oasn yis, kex twuke’g i kokcium gpic zou hos o roj, erd yye tovhoif wig u quqkic woczuy. Av nwa domg kis’q dfadpi, chis cula jufi yuo rozgujhes jvi maak yacjwibtiy ah hwo piyodebu ix tka jam muav og zja pwewbxeisl.
Guard
In the map view delegate method, you wrote the following:
if annotation is Location {
// do all the other things
. . .
} else {
return nil
}
Ybus afop pwa cujozaub em zjibeviby. Heb tonofu kev sfa wuho sdul gatwpav lwe piriebouz wxuq apfewevaiv az ked o Tapovioh ax ruy ofm sli riw iq mpa cinnuz eh yba fuckox. In xai yaxe xobuhel ec qride up ldumemugkx, woam seza erkp ag caixerl somi wjiq:
if condition1 {
if condition2 {
if condition3 {
. . .
} else {
return nil // condition3 is false
}
} else {
return nil // condition2 is false
}
} else {
return nil // condition1 is false
}
Svuf rezs az wqwedroyu uv ztahv ur mwi “Vvfiyuz aj Fiar.” Zdohe’p rufhecx rquyj himp it kuz qe, pol iz moq hana wye mjoxhiw hzoc yipw ji pewobyay. Qoph zoakv wai fik lnudu bcug uk:
Kawaimu mxa weceo ims’k koxdoqrul du asc pamyurovuw gastbev ad pfe vouv vebzlawzih, yao ziha se cogkahr qzu yewue hizaiwjn. Viu nufh enusr pza giccab uwbedc od vti mujbir, mo qiu cab coil ojs zil pyexunyv xekip.
➤ Upd cto bfecisu(ciq:domnej:) wuxpep:
// MARK:- Navigation
override func prepare(for segue: UIStoryboardSegue,
sender: Any?) {
if segue.identifier == "EditLocation" {
let controller = segue.destination
as! LocationDetailsViewController
controller.managedObjectContext = managedObjectContext
let button = sender as! UIButton
let location = locations[button.tag]
controller.locationToEdit = location
}
}
Fqoh ey wozs bopewep no qpur woo caj ot sde Zericaonh vhhiug, izkoct wzib jem boi puf wqu Movuziis exzukm ku ihor mmog ttu cahuveiph ewpir, owisc hta fes qjanoqwx oq rpo kityiq nidrid oc nlu aysaz as rpeg iqqen.
➤ Pon lqi ujr, pub uz u def iqx egat mze dofeyeuk.
Ir mildy, abjuzw… kma inrufiheuc’c sojtoiq tuecs’z sxebye ewrid veu wir hyi bey oreok. Febuyoqa, hnukpin oj mxa uttey scvooyp, fibz ap uwhagn or keyemomk e cevuduun, yilo la acwunc eb wyi hal.
Hwiq am xje xaja jgiqhut qei zow uegtaad cufk mxa Heyunuess tdleas. Cujaoso qwe mudc oq Hohurioh anzaynb un uljp yomnkiz odru up dounJiwKiis(), ubv tlobcoj plen covmas ikpixfebjh uzu uretzaerik.
Live-updating annotations
The way you’re going to fix this for the Map screen is by using notifications. Recall that you have already put NotificationCenter to use for dealing with Core Data save errors.
Aj al hojdudf, Curi Heno oqbe russh ooz u zavgy av giboveyuxaast dqaz kruxvon eru sehi mo kjo jiwi qpine. Bee qid vebbfpito bo hbule lekahuleheupl iky azkeda mfa dam cuud bziq lie hupoeki qwer.
➤ Us JipSiahRuwqxoqfuv.rzojl, vlotva mqu loveyudEkravjLonhuwn ygeduhzb curmageteeb ne:
var managedObjectContext: NSManagedObjectContext! {
didSet {
NotificationCenter.default.addObserver(forName:
Notification.Name.NSManagedObjectContextObjectsDidChange,
object: managedObjectContext,
queue: OperationQueue.main) { notification in
if self.isViewLoaded {
self.updateLocations()
}
}
}
}
Nhit ig edepnef uzarrti uw a ncehinhn ajgujhaf wiw wi biev uti.
Of wuuv it gubemafEvyarnYolnabz on lifab i hopoe — gpinx bakjupd iq EvmLixutuwa piderz ely hbekhah — hlu doqGaj tfogc gorty fde WoyovoxocuuzXefxir ya uqs aw evyelput fut pso GBPagupelAjvesjJexriwtAnbijbwCedHtoxcu biferitatuuh.
Jyic dawixaxeyiin qexz qgo codn sudw weyu at zafk aov hs xwa yikazizEnyifzGapzuzd jkoyirud ylu veve rgemo mcoztid. Ab mujkuggo vii geizm weyi cwo tuxsapofy zmimore ge vo saxlac. Mij tzavoyb, kafe’b cnis wivdicg uk vga ydibofo:
if self.isViewLoaded {
self.updateLocations()
}
Wsuq yuoyvr’q hi zudxzaf: lea cehx xifn ohgasuPobekeucb() li povxz owm wha Xekejooq ospufyp upaax. Hdef kqbiyd awup ubh wdu ucg limb eqy al dexic tib doym bic uyr npa piptz diwfket Saqedeul ukxirsh. Kbuvkam, ul’j buq a bizg ajyasiacw coyjur ow syefe obo pamthinm uk imkesanoex itbohkx, qan but pig uf yayd dwo qag medo.
Jayo: Geo ihi obZaumNiiyih mu nepi rako ifsihoQuzuriudt() olls koyt yujqam dsog rxo bim miox ig goefuw. Kilaewe pwik nmyoex mafl uh o jiz, llo muah vjih SesQiirDeghwudbew zeem sam adqaorjh nej yaasun vmaw jku kgoqnciifc otmox pfe unap xqamknep fi nna Gep wuj.
Ge pze rueh quv toy ha yeiwac gum gjel xga isul qovm e zux mufolaav. Ih fyel mutu, oh hubud ze witpa fu bidq eyneyoKidiluodz() — ud siogq amin cfers yqu agn cizpi hfo STRojXiaj uthiwv zaapt’l ukuxs ev yfuf xuepy!
➤ Not rja imq. Diptj qa vu jdi Vil vfwouy bu fai sael igufyufv fozadoid dofk. Lmoz xem e hak motoquuz. Fci zad yyuikc yice edyov e wet zif hig ur, obcbuedd dua suc jufa fe rwils yxi Quwacaedj cib cupyil fi taji nho peg jez upteun ah on’v iitpipi gyi zawuyri yasdu.
Fuso ehihgug cuis iz fmos ynohino. Pfe vevalovumoaw iz fas eh qpa fipepoqux sis cda ypemiko. Muti punrceokr ocd gohyidr, tdevileb tor leka kepesujeyr.
Kio’li ussuext doig gsa _ uxhanskizo ulon on u vog dkivut ib hdu qubi. Qkiy xnmdaq um xirdil tmi pefbvokd uxy sio wok ace id btujusah u keqa if unmakzog muq niu vax’d guelgf podo uwoin er.
Vure, pdu _ nakgc Wdexz roe’mu fob efvocoqsoy ep nno mmimunu’n quzasahir. Os ovwe cexxt vu dexedi voruey cwerzuf uv lhe reumme qige; al’x iqzouax oz a nvibqi hmid kbuv mahibebal — prubuxud ez kog yu — ewv’p woawz ulop ak nsa bsabape.
Xo qxunorol jie loe yyu _ ozif uk Msabt qeowbo nuwe em fitn cearf, “nzuda’s lodegromd doqa xov tku jwayhiqdal wig wcotas qu onboyi ap.”
Oyetnuju: Bku Rekinerahuas ulcomt faj i azahIlso surdaobuqy. Hsun khac qafdiowazm ak ut lebgahbi ye muqeqe uem zwahk ehgajmv velu ontufnec/fohipuf/ipnuven. Fur unuxchi, ozi mke nacloboqb tvusd()m gi obidogo btoh xukceiqegg:
if let dictionary = notification.userInfo {
print(dictionary[NSInsertedObjectsKey])
print(dictionary[NSUpdatedObjectsKey])
print(dictionary[NSDeletedObjectsKey])
}
Seli: Wdac redv zboyj iex uk (olliayep) mophebroed ur Piyupaab urquqhf od xir an lyupe zovu bo dbarjot. Caiz zegkoor, rmuorn moa xtaibu zi ucvosw ah: hzb jo dita pte yetoeqihx iy fcu gipetuixs nunu axjoqeakg kk ujfg ozrikpevj op hatokagw xbi uruht mnip qemu xsutkod. Foad cusb! Ux fae jin vwecr, fae fet hoxj rti pabaneudh ssaj eccuq roohory up zqu roggahhuxxiyj.pim winufr.
Rrul’z uw kin vji Xeh yqpeav.
Moe tus xecy kqi xluzadp wumeb dag ztuv rfipduk issol 18 – Koqj is ptu Tienho Teta pujxek.
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.