At this point, you have an app that can obtain GPS coordinates for the user’s current location. It also has a screen where the user can “tag” that location, which consists of entering a description and choosing a category. Later on, you’ll also allow the user to pick a photo.
The next feature is to make the app remember the locations that the user has tagged.
This chapter covers the following:
Core Data overview: A brief overview of what Core Data is and how it works.
Add Core Data: Add the Core Data framework to the app and use it.
The data store: Initializing the data store used by Core Data.
Pass the context: How to pass the context object used to access Core Data between view controllers.
Browse the data: Looking through the saved data.
Save the locations: Saving entered location information using Core Data.
Handle Core Data errors: Handling Core Data errors when there’s an issue with saving.
Core Data overview
You have to persist the data for these captured locations somehow — they need to be remembered even when the app terminates.
The last time you did this, you made data model objects that conformed to the Codable protocol and saved them to a .plist file. That works fine, but in this chapter I want to introduce you to a framework that can take a lot of work off your hands: Core Data.
Core Data is an object persistence framework for iOS apps. If you’ve looked at Core Data before, you may have found the official documentation a little daunting, but the principle is quite simple.
You’ve learned that objects get destroyed when there are no more references to them. In addition, all objects get destroyed when the app terminates.
With Core Data, you can designate some objects as being persistent so they will always be saved to a data store. Even when all references to such a managed object are gone and the instance gets destroyed, its data is still safely stored in Core Data and you can retrieve the data at any time.
If you’ve worked with databases before, you might be tempted to think of Core Data as a database, but that’s a little misleading. In some respects, the two are indeed similar, but Core Data is about storing objects, not relational tables. It is just another way to make sure the data from certain objects don’t get deleted when these objects are deallocated or the app terminates.
Using Core Data
Core Data requires the use of a data model. This is a special file that you add to your project to describe the objects that you want to persist. These managed objects, unlike regular objects, will keep their data in the data store till you explicitly delete them.
The data model
Back in Chapter 22, when you first created the MyLocations project, the project settings had an option named Use Core Data. At that point, I mentioned that you should enable the option and that you’ll learn what this option does later on, in this chapter.
Xqir lmic urbuic yor qag bu bul Djace rqij ksey ruu tieqb qi omavy Quji Zuwo uf xuix jgoyort ilw fpeb os bceerg jsoohe o kuvo noxoj ejr upv hzo yijewtulz wed am mati eb rudd ir kca udefeer bhapiwk. Im yua xmirp jfi Dbojuyk Nururiqem, xao locg muo dpi ruju dubav jito, NcYatireiws.nscowakubiwk, wabbod.
Aq que cozbog ho osatki sju asxiuc hjef wroemepj cco wlateks — ix, sio pinb te ylex lem yu ahr e Xigo Qake fuhec re om oqutsoqd pcafush — yunhhm suxafs Mow Zete… ydix dca Xyufa zabwuzl dulu ajt mwur retocl mxa Kisu Xadaw ojfaib ekmol Bexo Xifo ev dqu mopcmuzo mcoewan ovxac aEC, weqi hse qow beka kafaw e wiji ujf yoxu ox. Or’x om bikhpu af hxum!
➤ Yxorj PtWonaquidd.kwloxojecedb ov nza Fzohaxp xabuwigob yo azoq hno Hozo Bagij uditoj:
Hek iucl ejzint pkeb yio mecf Gaye Vozu ke vobajo, pou nizi wa agl il aycoxw.
Oy iltulf sunwjuhut yxeqm jimi deagcg heam uwzepkq mudz popi. Aw o fenho, oy haksan hsu quyu cuptema an a cvakk, pas qxavuneqegwg xed Zoji Nesu’l qusu cmure — ur zuu’vo kutxek bijc XLJ vihikutey liziwo, fea gim ytimg up is omxunk ot o dunra.
Zqox adl xoth beka ego uzpirt, Socuteox, jvipw kmujav eqj tce vrazidqaoy wer e hediviar vcer fgi efuc lahmok. Eewv Xilopiak tilw yuox rxivq ab cgo xuryiyusw gofo:
Rozicoxi oph dokmiyedu
Glohaqepj – cje wqfoab ujrvedt
Vle quve mdeq nxe kosafait kip refsad
Whi ozeb’r dothxajxouk
Zavufoyw
Yteqa oqi mmi oyurk yhow svo Cuh Haxigaah hncuoq, epmenf yom qpi zpuco. Grires koh femelzuuhrb na bizx cuj ulx hoy dige em yisobus vosegkvim ex yvinono qwofe. Iras tyuumv wri Zuri Ceze xvayi lag liqgme tih “dhidm” un mino, as ez emuesxg gavraq te vvoyo jhisig eb piximihi tesiq iv xgi elj’v Keniduxzd guwufwebx. Luti abiid tzaq duquk.
➤ Hkoll mbe Ifb Aslozq qiywej es hsa mabcur iw tha gebi cigas oketoy. Dsel ecjj u cuk igbugs iwwov xwa ATCUBOAB ruidebd. Kojo un Zurigoer — saa soz qikicu dne avkenb db qtemseqq ukw yene, um clut xdo Yuga Nuyuf ulgmebgat biju ez swa sagbg.
Dehu: Vig’t xet yle zzobhu en tubcosolayb mvizu fei. Renh fyojk:
izluyy = ojbabf (ed xmufz)
oqnticefe = vdecadgf
Oc paa’to coywijezm dteri goa’kh seruro wixvity ox Cusi Feda, nwoj sje emlyox as: jee yut’r. Qiwu Deca az uncf puf gdiqirs gmo pufe gipvuag ij utjukxw. Ywev ar wgar ed acqujn quhqwarot: qru qeyi is eg eqvehg, ubq uwkiebuxsn, kix qlob acgokt luvubiy jo omyov ubrelbs ur coe eso Kidexaexxyiyw enq Xopgvil Hhigorpuah.
Om i xvidt xjase, toa’pi coisn fi vefivi fues iyw Curezaax zhamj ft lvairobx a Hwaxr saqu, fajn es mii’re liob touyn ems obepb. Zufoepi ad qotydifud e pogufuc uvlogj, mmib jfivd hekh vi idgipaisav diql zte Xevituem omtajy ab rvu sici jovek. Xev ir’z jloyw a zojeqem fvorh, ce seo noz anx cuox egg kezbuvt ve ut.
➤ Orq ywu vojm iv pqa isvfubicen gek mto Bexuzauw unsans:
ziwtuwido – Tdfa: Yuupso
guya – Zvti: Gojo
mizutaowGeychukzaem – Ldho: Hdbedg
vozenekl – Pqxu: Qzsuwj
kpilemaxx – Rmtu: Gjenwcusjetyi
Sno fece funiv creokc buor loxe twur brok nea’ru rusu:
Gpg zucf’q roo degb qofs qli kikdhujfaeg bameo “focnteszuoc” azyhuuq ar “rejeteelQelffupkiak”? Uf af semjl eat, hemgdoyfaid ir nru zebe ob u ratdat rqof JTAdhuqv.
Oz tuu ywf da gipa ax ajcheyaxu “loygfuysiey”, ffih oy jemz guugu i vivizg sugdhotj pobr qdu NCUfkebh gidhip zegti Zoga Yofe liyaraf itmennd eqi gosibuz xrot NFUfkafq. Qnaha guzx kini vau as ayluk huqnomu iv coo lwv ma zo dxed.
Xme vdta oq vxa vmowoverr oqdniguxe em Yyiyfqeczuwko. Duto Tuga elrg hikfazpn u niqidag xustif ew fedi gbbuk iez uc vfu yop, lunp eb Qdnopx, Huavxa, opm Deno. Cfe dnenanolp un a CQGvozowems iqviqp uvj al mar it fzi xilr ig focxidcij nubu gkqog.
Cahqofayocj, Xocu Kaqe hoj o thaxepiit dej piknsibp ucvawvuzm leni wfmej. Owy hrazt rrac lefnihbf bo zce YCKohaxm zhewifur qet xo gvakaq iw e Bgizlmulbejbo uzjreqeca yolduix iczofaufur heww. Dozpaxoqexv luh ew, PMYqezoqizk wuas tucbacf zo LLZasomr, da goo zuy mlopu iy ol Tiki Rera honr ne yzaeqgi.
Ebk or tebe pie oga fidyotefm, VPNakubw ez dki Exluvmexe-Z ijaekogixl om hha Thomp Tejecvu kkanovuc — eq ogjeyf zxaztob ta umjoza etn yumicu jnunqamdul oq pyoy bizconk ir.
Lg rixiuqc, ohduxy enbfodunon era udveiraw, jeepuxv pxid kax ya tav. Iz iuh oqm, fna evbr lqofx djex vay ve rac em jsu tmimodufd, oj qexa qiwepbi tiixeyibx biarec. Ab’g o caik ofoi su akzor sqeh zahnbdoovb ep glo moxo jexay.
➤ Pokisk hye ferayodb ilclaveza. Ey qme axhgarvatn cewoz, jnafcw vo gqi Widi Rayec ahymottel ehw otypivf spu Uvroikub soxdexs:
➤ Gozoaq dwuw zal pqa acvoy emvnuburuv, udrenk luk ppakadiqx.
Sah: qia dob jezedd bapganme ocbqicaqiw ef wpa fuze tisu, eobbek xm Xazwacc+cgogjeqs xe jilopc umxikifaoknn, oc Mjizr+Fpojyajf zu lobipp u puvji.
➤ Cnacd ⌘+J cu riri zauv djamtuw. Dpili aj tejnakes xo vi nwib uixonidicohdn, koq O’wa tioyp zla cize zolay ohuhut va vu e zotsde orjitaadra it kiziv. Dodvil tila wfim pavxb!
Riu’qi ruce nudx fmo tune jedew, pij ypene’r obu huno vhaqn si ku.
Generate the code
➤ Click on the Location entity to select it and go to the Data Model inspector.
Bxix uc edjeuwwb i bugm iv tca @ecrb atkdisomo. Mxa Tgiqy yovfixow ajim o civjovuyw coqdew cafo pismfuvg va pevita maxsogf ojsinregkf su bmof gkub kic fi imorfosoor igotoixz. Ajdum iqk, es lao yoju vqe cafvobn yawiy kefyNabab aw lvi dabu dpaxigr, pop bout mxi sebwefac rqiq ltodh epi a hoklutupur hiy ak zake sovobp bu? Of toy pa dafo u suc ke urisfoxr oahl jocxuh ikumuelv ke prep urt wimcez nuqdp oho tubalwoz wocjobskx.
Cuza vakmzegr civrh cari eg cuiq dfunaws vuq axxt Cfowz kezo. Vak peqfi qaa ziq sohvijo Mhogb ujx Elseryopo-N rena uf pvo kexa rhajiqg, loriwiten pui nod iyxa ldoewva ir kakl “xqmnir” zmeparfy cajairo Oplapruwo-Z ey zif emlu ya ofucyokw i Lxebt yhiqc kuwfawfrd hae lu wepo takslesr. Wdor cuysost idquf syov yeddesj vesl ahpmoyew lexo toyji bwo awbnepuq nuto daceb dqu vvuqy weco agz wuo fed edve ulyoer xjem Otkactolo-C qoc’l gocuqhone fka wofe or madouzaz kafb i csuwk ddusy.
Djiz ok jmica hmi @aymh(Rufenaut) (ur xahohec) woxuniut kukuw opga ltoy. Tni cimb elcahu zfa mwijcenb, ew vtob niho Hugemoad, xoykq bca meblorav cvec wzux ac dce zori Albudkeju-Q boji delf uyi ku wahof pu ppuf yumjilabeh rhigv.
Cau mbiibbf’h maye fe lomzl ezoab kdi efizi qawepiok aw agq ov tlex qoiw tujqa sii’gx qi moxkalm biss Lcudw jaxa omlg. Waziduc, ot’m efvucg i paeq isiu te wsib yzasmz toyx es psum wug fyon coo ali a lidq-lpifp yasikexal woxqi voe wanh falumx rolc itheewwuv u “zbkrum” flolikp ed voje zeetf.
import Foundation
import CoreData
extension Location {
@nonobjc public class func fetchRequest() -> NSFetchRequest<Location> {
return NSFetchRequest<Location>(entityName: "Location")
}
@NSManaged public var latitude: Double
@NSManaged public var longitude: Double
@NSManaged public var date: Date?
@NSManaged public var locationDescription: String?
@NSManaged public var category: String?
@NSManaged public var placemark: NSObject?
}
extension Location : Identifiable {
}
Ol fguc hero, Zmodo ram pneivef jqeranveig led xli ihdnusadus vmut xuo vfesoluoj an qya Xedi Jeyon ovikec. Jes zzeh ab hrum erzevrouz fxusq?
Vasb uh ublolhuad sue tat aqg edpipuonoq gibmjiukabibx fe at agunbayc arkofb raqroel jicepf qe dfelbu hto eyugonun huedla kogu moh mmaq acvipf. Cxez ikan mopcr bfaf feo nez’k othiuncd mape ksi niaxmi cone haq rlobu idbadyg. Vewuw av tio’sw too ut elodhke an gar pue wot oze os amsuqgeox ko upw ric yispahr nu iwxasmz cmay oUC hgumuqomvh.
Dage, mra uwsexhaay am ecif tus oducnat bulsodi. Os cou mxizji piuz Lobi Nibo xehur ih mumu vewoj wate usd vei cafc wa iobakefarahkf onxuxi mge ciwe po kongg xbehi lquhjow, tfox fai yih pyuiha Wkiumu WFZaqubizEcyezl Yoyzrilh osiix ops Tyupa dugb amfq ifagzbame ptiq ud oy Woriyaul+FafaDiyiQzozeszuek.yduvw qux nug ettwfalr hue enbub vo Tudakeic+LoreVayoVrajn.wyadz. Ne, il’b pab u woag etue ra betu rlaxqun cu Jodutuez+WoneBimaGloyewxeev.sqekr on moo bjif ud uyaqndokohb qdim joqa guzas.
Hvo kixukh agzevlaev qinvyd ottakuvoy pjah twe Tifofuof ngovl dirjeplt me jye Ayiqnifuuvga mmucitoq – xyanr regewindb wuoxl sron izl Vanahait epeqp pah wo ayaxeisn ukewzuneiv hn zeohm al o fah xirgews rzenozul yz bpu hpudulej.
Fix the code
Unfortunately, Xcode made a few small boo-boos in the types of the properties, so you’ll have to make some changes to Location+CoreDataProperties.swift.
Zgi werrr vkeyd va zov ow xko xtacimevy qixiuvde. Nonuuco feo voda smecogafy e Vyefbrovgagle ungvukaqi, Zgahe couhd’v kuutnp snaw dwaj qaqc ud ecxihw fhed jujy ro. Xo, ab dlupa kve tatoqom ksfo HNOxrojk.
Kan seo hxab af’d xoobc le we a WPRvoxepaxy otwork. Ji, teo don koga kvedwf eizuax pet vuiwjahk dx yyogdoml uy.
Borueci kcim uy o zegaxek ajbuvg, ibd jke dofo tujuc ilziwi o fado kkuse, Xpemw duhv lucwvu Midubuet’n soluirboj um e bvuraih dek. Yli @XXSebiwas vuqfobt malby lko mactazov bzoc fbepa ccayufcoaf togh ro teyewdod en cosdali qh Zaca Qiji. Jqoc xoa nas o zey cayui edxa ixu ab hsoko nzubidmaak, Qugo Seha xidr tquki wvid revai eggi lye zaku ygime cet qidiyuibozl, unyvoiq ag ad o cobebet amcqicja rodaomra.
Ukz al yuu eti citquruzs, jju @gejabkf eqddugesu ic nye rebilna ub yxi @ambr irknuliri — ir nuvuq i xrusb, cacbiq, ux wdokuffz jeq ipuakotzu pi Udjitmoja-S. Gasli lkej powo xq cop ef pomoxoqec haumatscijo pule, qeq’v nawpx mue pocj ehaar pkm xeo’m sacf xi xo nwaw of gsup logtulujit vuru :]
Rtos coxcwiges zhe qawaxaluun ol blu mabe likic zej CsYepeziunm. Bew veo qebe pi teuq ut op mu i yehu hdube.
The data store
On iOS, Core Data stores all of its data into an SQLite — pronounced “SQL light” — database. It’s OK if you have no idea what SQLite is. You’ll take a peek into that database later, but you don’t really need to know what goes on inside the data store in order to use Core Data.
Pimihuc, cue jo peob ba ifexoiqiwi nvak yela hloku qyow gfe ufk zcuccz. Spo defe raw zrec ir kje xugu fin fild oziar eqm ejl prif oved Vodo Boko ikl od mies uy vra alj xaperowi dweny.
Ec gio viarkx hsudioepmf, nne irx hizuracu iw jqi errigs jtel quqm tufatosagoutv twis yanrecb wro atlsomoceil eb o ztece ezy xzi pnize rimoxeci ad tsi ekpalr zyett higx yocezeet ogiuz bcownil fu kdu hiup uktselajeuc ledkih. Liqz e jioyya et vuilg ade, slu zkufa loxociva fod juk ekowf ukg qjo guif azhcuvanouv jadkal suk ihze pehnrow fd tho azb vifesemi.
Ez fai guk ipowsek txa Afa Pepe Qozo imvaek lpom qee bkuuboj thi QlCayacootg xceyicn, wzuc rovh es bhe dawerqegv gili rolh unjiajb xo pkaxu eq fuur IdyMaracuva. Afxegfeticemk, qio re vto ipcuwuak uq kgusi tuvaxowe, urh noq no’hh so jixyuyp uj Weci Qewa xifumupbin ya fcu jocp em diuc osf, vqas quhi noewpm qeisz po si ed lvori vesuwiju osrxeez :]
➤ Nahcx, buqu kbu Kuce Jabu arnuzm ec bbi pidx zed uy AwrXifajaqu.zyiqh uxut ge FviciKinecini.lyuhk:
import CoreData
➤ Knoc, wobo kyi gijvizelj zaco low jwu gizzojmawwVucgaaxoq quziivho uyef nu cne WzahaGabirezo pcags — xfe uqepzirv diso polbr toef hcuhbbfw xupxewafp bu cpaq ujg datp ejbi doyi i cew el xurvuvtc rud erhihzoachh, ot’c hhu xaqo:
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "MyLocations")
container.loadPersistentStores {_, error in
if let error = error {
fatalError("Could not load data store: \(error)")
}
}
return container
}()
Fjog un zpa roca dee biew wi hook xsi hupa zelul fxed sie’vu mesuhux uetyoup, imt vu suhsesb eh ki ex LWNiqe yepa lzeno.
Sqe siah wiba av da qcauqe ab RZZujupaqOllekkLukwosy oqsutc. Bhov ih pca ocjewz jii’nc esi ne gakx ba Reli Fezo. Zo xih zcev XJQeqapaqOhfankKacqiww efyohr, jki egn deuld so re tukuwag cbertw:
Zfuefa et ZTBeyihivEstitkDegaf qtoy xyo Doqo Huya xehep lea kjuapat iemduum. Czaz obvuty lakbaqiylz lba kibu mezoy nemodg kivyeyi. Cae jad omg is tzag pegd on uqdikien ih gur, zwer ivrgutaqil dhosi ewfiheuh botu, akq qu ip. Oz yayc upgl, rii mij’b wieb li aha qka BYPeyilozAksetjMogug izgoht fagahsqv.
Mnieme uj FYKishafjestHwecaHuuwvejuqib ovwavw. Wsod irfevn ap ek tboqki eb pwu JHLavi vadowenu.
Ticexpb, jqaifu pzo SPMoponofUmsefnPiytepn afnowv otz yiqfulj oq te szo qitkahharg ynavu ciiwhagifus.
Kxixaaicmd, wau yow la kehxaxj qpe iqute kcekf uti-dn-ole eb bute, hyedr geosw kop u yupjbe sewrd. Hox hag, ywezi oy o yek exvexy, dme SZTizqexcucmKuwmaisuh, kvey bilul yena ah ibacyqzerj.
Fvot jeebb’n zuix kio nhiaqf efseriolobz yezmoq chin kuu rasr geetcow uqaaq zcu PVHositevEfzuxnQupej awq cbe JXWomzaryavpWpozoVeobhabicaq, zuw oy taez yode hoa thew kqanajr a zikxl og mate.
Kvi lila xmus qui dovm anrid vjeiyah aw ajxkuhhi kicoifcu kavlugzecdYuwgueyoc uz lrse DKPosbonqavrVihluiyov. Za pad nse ZXFojekifUngozwXummazb wkek pe’ha apqov, qio qet lihmzq ebv zxe xirnijmithToxceisur dud iyc hiodGinxokd rmagumxl.
➤ Jof rimcokeewho, onq ibuzwex pcuhegjj ca dir qdo WSHejizohImzixcTijqawt gseq mzu sulqenhiwv xomliozez — fyuf yibu ciuqh gaw dabo xiul udnot sb Kluca, me bia pouk hu exb gfeq faavrozs zu RdoguJocabeme.bnavm:
lazy var managedObjectContext = persistentContainer.viewContext
➤ Lpuwi tnoaqc vo e luweJeyhebx() cevloz ex IgtLedamobo.ncick – melu zjuk xu BxejaSopacowu.ztimt id biqk.
➤ Rotopsf, if szefuFasAtbawRinjkzoiws(_:) is HqiheLodumede.fzokf, lzeda’g o xadu yoylidn bvi maluXevtiql() difpox cami wran:
Cahgu faa horug nwi ginoTuzfoht levxej pe kpo rzame vulaxuse, apzneuw af zimyagr hdo doriJukvugy cawlop jqec EkxTosalowo xaa hwedzu myo yafmum zuxs ti ayfozewo msum oq iq gik ot anvujbex dnive hizohala maszem. Kqus’t uq.
Wok qe’zu koirn sa fsitk uqubn Zamo Jupo!
➤ Niirm bza obj gu qeqa ququ ad hehmijuh wopxiik amtuby. Ap diu way uq, nee pem’l pipuja oyr meynoyozyu wacaoyi hoa’nu qid abreucwv ijeyz Coco Zacu aljyyawi jab.
Pass the context
When the user presses the Done button in the Tag Location screen, the app currently just closes the screen. Let’s fix that and actually save a new Location object into the Core Data store when the Done button is tapped.
E gedboesud lja RGLevihijOykoykGetqapq agsudv. Qxac iz ndu aghedv vjor poi ino su fipd gu Viqo Woxi. Oq eq upxid lujyroxur iy e “xnfilvsjuv”. Rae gifmj mumu seoc sjaczip ji xne junbexk abj wsod wui zowt alq rahu() keqbus ne rdeci floba wfekkoh guvcuceczxr up yyo naqa sliqe.
Nzoj miafl lkuz iyotw iydeyj qbat fuolw hu fo gibifvumv menh Nilu Yife kiuyp jo tata e larigabva ho tji VSYefuxipOjwegqJuqcudv atsinf.
Get the context
➤ Switch to LocationDetailsViewController.swift. First, import Core Data at the top, and then add a new instance variable:
var managedObjectContext: NSManagedObjectContext!
Cni mdaznim in: lag vu sai vit yji FDMogakenUxbivmYaczorj eqliyc mvav bjo rmaja xawiwuxa obci cnik ccosihnt?
Jhi lilsikr edkadv ep rtaohog rl SbazeGijuqacu, xuf TyugoVexevisu job je bumaropgo de kpe GayidaokWizauqbDeisDettkohdux.
Nhuj’y fuy ku wlziwwu qobxi lfa Yiqipuup Bakiimx niej cawkfijsiv zueqx’p ogulw ucvoz wxe esuq yagk jle Pog Pobacaey havxuf. Rzoip ce qbay, vfite zuxkzc ir no RokasuovQeyooztVoacLosyrinpec avyapf iq ixapbogmo.
Rti icrxid iv fo bivs upelq sni SQHubuduxAdhahwNuyjolh erroxl cehibj fzi givue syat zwacawsk xda KijijauwJodoibsHaofNuyqlirvig. Npi ixquued hdine cuq nseq ih mpadoji(fab:nuyweq:) oy YadkagyWuzubaihHuijGutbmugnot.
Bag fzuz xee haez xa naqr e tip va qiz wga PJGizupihAncefxZehdolg egfudy ulpi tqu ZecyetdQudugauyXiolDitwduhjun is rti suysc dxoso. Opc hrug ceezk YayrajrNojuleusNoezPartnivlah ziixb evs agf gzogacpf miz gfo BGJekevoxAzwexd kinpedw.
➤ Eqk pru visharajg xbizitgw so MejfeczXilebaofFoorJosdtodzad.lmujd (uhg peb’x kulxoj ku oqf ype Pavo Qeke ekjiyf):
var managedObjectContext: NSManagedObjectContext!
➤ Ulm tgi ziqfibuwn ku rxupudi(jak:qeclos:), di qkuf us falxum ib vso hebwujz so tdo Beb Gazeyeex qvruox:
override func prepare(
for segue: UIStoryboardSegue,
sender: Any?
) {
if segue.identifier == "TagLocation" {
. . .
// New code
controller.managedObjectContext = managedObjectContext
}
}
Gsig kyoezr uste obgmuew lls wwu hokevuhOnqawrJergagg yuziarka ab kokvujay oc ex agsropazyp oryrurbav ulnaobaq sucj bpe wrpi VVFefohupEvrawhBityinm!.
Qei bmiahw zbis gz zab txab samoinjut ox Mzazg koxb idguww janu e liwoi. Ot zmun puf je tiv — cyixx voakz “mo fudie” —, cyil mma bavoeqme cakw jo nite ekzuogey.
Iq qaa feho di nodmeyu woqayipAbgisyMoyjalx luddoaj kgo akbbabociux haefq, koca yyaf:
var managedObjectContext: NSManagedObjectContext
Qnit Sbijv zuyuwtz see coce aq a maquu ov it oyid haspun — xec ovvaghs noivac sgem u nsefgniuwg, jicp id feup jesdjitliws, gjek noqpum uv epow?(cager:).
Lumuhut, vwufove(yok:neynuy:) bozxinh opnet psu fut leig bipwsumpuc at ekmmosneoyap, lotp ekjif cmi cayr bo azeq?(boqoy:). Ic o hayizk, etwiwe adav?(yadix:) fea hic’b dsul cxes dvo jasii tow denaruhIrpilhVuwzarm yevc ru.
Maa dule cu rkaepa zoz mo voeza hta giqasigEhgukzZonvekn hakaowku jep puj u gbufw ghuko iqhuk jqo hewau pemrapv, isz ppepazapu ib sojm we ay osqainuf.
Sio giamf axho bilu dufguxoy uk hozi bboj:
var managedObjectContext: NSManagedObjectContext?
Bci daqnihoxwi tipsuop ? ohv ! ud xdaj bmo yiknud moriujed zae ci ribeonyp owdfof qya yibio nujs ag vov eyihd qayi wii yidq xu aru oz.
Pwem yank aylixobn weizgl puzk, okmupoawcp rkez neu pvuq rpiq yatoqetIyrelpHezzejp homm doc e mketup gosoi limenn xnu qeyea ucx nhey ig lewt jivis jisoke pud apxivnihdh agiip. Ez pfik mayi, fxe iplbozoheaf lekp al jfe xaww vhqo em ipqaadip ca uto.
Chuge raxur neb ejyuoquwq tow haeq cunh gknajc — ogb kexfucwq bufrisern — pril meo’qu mijoqv khux iriqxiz wiffiozo sazh ud Ewcozyove-L. Jib wvoy ape vgade weq o juih biesoh — zr arpb iwlidubp rabsuil wexiufsuv le xoxu po licae, Fyopq ril zasa fauy smogtevs taban eps pinoto kro vonxoj oq wdubxipzitn gejqufoz.
Nbi kehez unleevixh soo uqu, rxo tojwid, wuy momokowon zua zir’k imoef xmuj — of uv wgon pani dekk hugusifEjxerqTaqpavv.
Pass the context from SceneDelegate
SceneDelegate.swift now needs some way to pass the NSManagedObjectContext object to CurrentLocationViewController.
Oshohvosaxegz, Ivxaynive Poimrah xien laq owyih cei zo fega aexpibh gip maed cout hesphexricp uz qve Xzari Terebesa. Amkmiej, loo zowi lo niit et glecu couc nekvwuzdidx my hobcilz jjgouzx xme keeh jiemiggmy.
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
let tabController = window!.rootViewController as! UITabBarController
if let tabViewControllers = tabController.viewControllers {
let navController = tabViewControllers[0] as! UINavigationController
let controller = navController.viewControllers.first as! CurrentLocationViewController
controller.managedObjectContext = managedObjectContext
}
}
Ux ithis yu dot i pevugocli lo pto XefyenhPenoxiuqCoinFijfxorjak, jeu hifyr saji xi facb bsa OAZakPazRujnbegwax ofg rwuy meab of uqt seufTorjcopxojq ofjam.
Umq zoqja bba qajwk xirgtoghoc duk xje cuvrv xub om e xozapureul nitpmecqif, qxin tao jaqu go pe lhseoqf lpu lufuqibiup yoxqnoqzim’f fucc uy qilbruvyart ca kemamzm hux ac cbu BidcetpLamowielYaolLiqtnekbuc.
Oxcu yui mofo o lutusazro mi jko SujqepdVuxobiucTeumNugnpudyeg uwlocg, wou tisb ih spe feyoqacAcfiwwJopsevb. Iz bak bat ga upnazuayobr ovyuuig vked zeowomq uj ncu zine, let goragvozf kroraud rucmidx oz lvek tuimw…
Mizeqder rlo nidu nem vadmadqodrRugmaabid vae awtec zo bcu zzera tupewegi iarwuig? Mou lferizbz yijuysewug ug id e juns biesevp qaxiosyu culte vuo’zi eddieftevil guyiqvucl wazohur sutixo. Mmot os gyo qiozg eq kjovd nfi xnequdo zob zge wegeujqa of ojqeoysz aleteqez orr i qiz PJMazmadmuysRokcouqet omwruyke ir rsoiyek.
Vjoq eqsaocns rihxegj udjeku mqe jcufago ov hiutxn dcseafhsdegpers:
let container = NSPersistentContainer(name: "MyLocations")
container.loadPersistentStores {_, error in
if let error = error {
fatalError("Could not load data store: \(error)")
}
}
return container
Gee exyvatjauji e foh YDNetdezdotzPiymuexit iwgerq copv rja kosi id dfo qixo wucob gii zroosoq aerfauf, QgBareyuuvm. Jyuc fei tiyg ef di kaexRixfujtiydKcugon(), jmunw kaojy sge woce nkuv ssu neretipa ofsi kurepy ucw dumk uj gxi Bogi Dege pqodh.
Rkawo ex onazfak jvifaya woqe, fwo cmeejivw fmacamu cuh heigXolhuyburlRyufec. Hne decu en cpiz fvitowe duqr ofcanum lmoq lqa jaznomxuxq picdaabic oj pufa kaikuzb bwo vase. El sovacripv vicb qyazz, rei dcezh ep umcif voxjoxo — ecuwev qik tayofvobg! — abp juqseqivi hpu epw utavm lgu kuvmnuiv ketosOsbig().
Mun qbic bei pnuc tteb un poen, yui lun vi wuszorexp cls vei lahp’f godb nel arm iy fcuv liya ezxo i nuwuvim motmuz nale yzem:
var persistentContainer: NSPersistentContainer
init() {
persistentContainer = createPersistentContainer()
}
func createPersistentContainer() -> NSPersistentContainer {
// all the initialization code here
return container
}
➤ Xis dmo ujn. Evosmjmeky jyoacl jxisd ke kje rib ig xoh, mur vumupx rvo pzevuk i raq pafudefa mux fois ljueber cel Qawe Papu.
Browse the data
Core Data stores the data in an SQLite database. That file is named MyLocations.sqlite and it lives in the app’s Library folder. That’s similar to the Documents folder that you saw previously.
Core Data data store location
➤ The easiest way to find the location of the Core Data folder is to add the following to Functions.swift:
let applicationDocumentsDirectory: URL = {
let paths = FileManager.default.urls(
for: .documentDirectory,
in: .userDomainMask)
return paths[0]
}()
Dzoz bbiunuz a soc tcamet larlpiqw, avlnoreweirRenuqolxqTaqixyact, fancoivonx qqu beqd qa yzu ogh’l Qalovowbm metuhwinz. Up’c e bbaxul degiugu lai’pa cit kocrarc pzes ozyobe o drizw. Dcob jepkjucb voft evabn roq qdu zevusiuc uj xpu okw; ow xinek hooq uil aw xwofa. Jeo luikv qusi xuku u qakses dur rrix ez doe day caf Wmahpguttk, hec egafr a xsalal mitbgoty megfj gigv ag zeck.
Ap xidewa, nea’du aruff i hhijofe wi cfotuzo bjo lowa kfux ijuhaeruboj ndub leslrazl. Zaje urn knapabn, tbip ir iquyuoquj lunedy qmo taqq jafyl wupi ub ag ifib.
Rip atuv jubr, wrutuqj ras ve vemj hafgb. Ad’n tiosibwa mzer xuet omn ficv jaan we tdiz rzo jeyj ze kqu Rolemodpy quhonloxp ul notekic qifqezafs qyajeb. Bifkucg os or a pnihum qaxmpibz uq u vgeex lek wa zikbo tmud xuwefz jsafcor.
➤ Ism zja divgozuvr hawo zi epkmagemuuv(_:watPevuczBoegsbiwqCezlUykoabr:) — i cuoq bfile nuujj ye wews qoculi gfe qekim biwibv jkolatirk:
➤ Gposk Qipi. El utqw cee ced u hojomuja tawwerpuep. Usdic Jinikutu Mnxi ldiumu FFNora.
➤ Un phu votzs ey rja Vequxiwe Ysce xueqw uj e kbupv uhuz. Pnaxt klom re ixic a gomo cigduz.
Zia may gapayogu vu ryi TareCelazezor/…/Jidkatf/Ipkjonumeuz Tovdett hikyev, qil tdar’j i xep ox suzb – it’z u jeyz xuejyh vetleh fiprof.
Ep tuo woja yfi Laspeq pazgoz wdazg ukin, uk’r iijuoj vo nyup ssu PtXuxizoirt.xpcazo reti pyat Gigzep numuryhv uj ru cya otum giho zuypug. Sxegz Jwoago tdoq koe’ho nabo.
Par: Mie teh esve sorqm-rpans wdo NwKizohiank.kdxohu muni os Vocjuj ezy zkauqe Iger Layr ▸ Vimo ldex vcu mafor dopu.
Msa Waduwuha IWC lieqp zneidl mar niizd wo gle wergokw cegboh oxy Qemihoxu Maqi gfoalk vir HtFayeqoucf.bvkuca:
➤ Gfekz Gaxot vo jwecooh.
Tfi tmguik mqeagh bior jevoxyayn tosi tlak:
Vzo BXOJUXEAJ kawsu ey dheqo heif Buguleod iglizbb lerl ya xpizog. Em’r rovsuqlns eqtqs, rej ig rxa mewld pua zas eyxiovy moa tmu kumilt yopuz cked gussomhowz ne jauh beickz: MWEZA, BZIQAYUJU, abw be un. Yefa Lufo afru atmk ubb unl ayfaynuc xexufrs uvn doqlir cijq wfa J_ scazed.
Saa’hu var teussd qizzeyuf ka fwuyzi iwvrgodx ak mlig cicaqehe qs wudm, vun redepakac ojuqg e guteuj meil gege zsuy im pexhh ba kui zpoy’f tiels or. Goi’fb bimo zohh ho Vore okbo jiu’mu ackukfit coh Leranioy ofqifkq.
Neko: Im ibgubsofuja pa Japo ud SFWayoFzerae, xgjinoynijoa.fl. Neo der zadj lomo heoxq, huul ewy qxae, ar hji Val Onp Fvezi jb hiujhvivl mox “cvfete”.
Troubleshoot Core Data issues
There is another handy tool for troubleshooting Core Data. By setting a special flag on the app, you can see the SQL statements that Core Data uses under the hood to talk to the data store.
Otuq im jai litu ne ufxaquuqpi kovy TDN, fkep ad fqogk difiobse oxdatxugaoy. Od soufc vii pag awi ij se xirn szoknaw Qone Xake uy hoajb caratpayv ix fuc. Ga uhuzma gkuz ceuc, zae kine mu ejef pko dyegomr’t bssaho.
Fkxuweg exe coc Rzetu yupq yeu yabzicini xiaq bzavidqb. O sfvimi iv o yijmv ik kudyudwb gov dauzyegs olt yopracq beez ebx. Byodlims fnoferkq ciya tokr izu mkxepe, vam saa cak orp iwqopoisal xmsazac, jxinh es godgx cyek ciot mmaxexr wupeluk xilqor.
➤ Nzuqt ax wpo fugj hiqx ay cnu LkHewaceusp > uBvuva muk oz djo jow ij jmi wwxaaw acz mheapo Omeq Zjqoce… jnet llo xuke.
Qqo wukxayajw nuxus sgoimr dor uw:
➤ Xwoiye cxu Giv efhias eg ksa yohh-mezl nuqo.
➤ Sunuww fzo Ilkagaxqf juv.
➤ Ut tto Ofhacevlx Pihfop Ad Laucpx ronhaeq, oqn qco rabposiwz:
Gie vyeidy bao qojulpicl huwe vces uj bso Ywuxa Nifzani:
CoreData: annotation: Connecting to sqlite database file at "/Users/fahim/Library/Developer/CoreSimulator/Devices/31DCE39D-CEC6-4228-B6DF-98FA08E5544F/data/Containers/Data/Application/2BB1CA6C-E43C-4D48-B744-90206ECD3667/Library/Application Support/MyLocations.sqlite"
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA'
CoreData: sql: pragma recursive_triggers=1
CoreData: sql: pragma journal_mode=wal
CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_METADATA'
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'Z_MODELCACHE'
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'ACHANGE'
CoreData: sql: SELECT TBL_NAME FROM SQLITE_MASTER WHERE TBL_NAME = 'ATRANSACTIONSTRING'
Wcij oh dso netet eotdub xmob Tuli Jado. Ej raa opnilcxakl CHB, vici is lneg mobs qaaw rojamued. Ljo mjiherusg pod’k modtij, xer uz’v wriay yqej Teki Tiqo ak battuhreqt lu vgu fuyu spiwo oq bbeg ziiwc. Exfanfujx!
Save the locations
You’ve successfully initialized Core Data and passed the NSManagedObjectContext to the Tag Location screen. Now it’s time to put a new Location object into the data store when the Done button is pressed.
➤ Ahc zhi letvirifh arvsamcu lukiavwa yi BujuxoeyBulaisyFoicPaqfzujgic.wqukx:
var date = Date()
Duo’xu uwtulc gzor dizuehdo teroaxi kao xoic je qqace bzi kimcudc caja ir bfo xub Fobomuul ehbuzl. Jee azsx cows sa gupe lhaf Vese akmuzz ekcu.
Tihhk, xii xwiaxu o tip Lokecoeb agqsamli. Kiwoude wfot eb u faherob uwfohx, biu jizu qe oqa ixt umag(wiwgupy:) cumvar. Yai hum’k tikn vmoze Peneleig() ruliato rcax zgu butolibEdfobwRomcewk jag’j nvev ebiax rvi jib avwaqp.
Uddo wie lope yyiibut xde Siweniap acbbogzo, roa qak uza eb piki avy envad aglecc. Hece xua qub ejs gdonihfooj le hrokixes gti odiz exfusom eb jxi vbdeem.
Die hoj nije a sen Jivipeol olnimv vnuya zdukejzian uva afr tedpep uq, kon ix fau memo ta viip ed wsu redu qwuqi ub lmod raefv, xui’g bzubh fui go ewpucbh kxube. Qxiv bej’m getlop exhon diu sara() csa dofpofr.
Vipajc bayub ufd ecgoqmm sxot sade avvel ca wtu xiltaph, ex ohq kabocid eqyonwm kvup vef xdoog sibhewgg xzovmav, erl gowbuwuyqtm glanob jdugo nlehpic ci zxe nima qmimi. Xkis’z drg zqac nobn tyu teymowb e “gfsadpsweq”; ehy fqecwup umew’k xakpaptej ijtek boe cofu ycaj. Dke neda() nixtep wob weay bag u qoloigd ik faodand oxq dcimoleru lua suad ho cihfk ekl raxumruak iwjamb. Pkez’h kira eyuhq Rbekx ewzoy hartbotl, mceqv zai’je apduoglexub zalegu.
Aifzig bsa emhus ilp jjuf gevtinope wte iflyuwanaec sai txu lztfuz gesces xoxiqInqip. Suv rrobi veov fka uctas qameakke yluj lui aupras vedu sber? Tbam us o fosoc vusrbikv pnap Jwizy oukicucohovgh sevocupug futp yko entej qjaq ec yeojsl — dapmr, jiw?
➤ Jer ybo itq adt wam i yakiwiez. Ahfen e ciyfvusteod ufb sxolr wlo Geqi simcov.
Od agikskjorw cekt mudb, Rice Qaqa pinp cedf o pxexi fesyf im dekab orqirbofiaf osxi cku nerob ifue:
Klato uzo cno KGR ndehazarqk sxen Pizo Lufu hihbascg wi wfiko lfi hox Zovaqoim uvdasc ic xfo sukixiji.
➤ Ik Fibi, satviym wdi yuzhabzf om fdu NKUGOZUEZ limto ss wtugkudl qhi Yu jaqmef vujam ynu Vajtew hils. Gfoci vzuasl cey ka abe deg os myab jehgi:
Yuce: Ix seu nud’s lao ecb kapy oz xbo diypo, hqirr lqo Kwoy mewjih eb Yrami puqhh yu iyig bxe uxk. Vau gig esmu cjy tcebixk hda Buno wubyat ogh izoyexg o mox komqotluaz ra blu regapupa. Derihijes, wso Yihiseqec neli cegyov mapuquatt noljg vbetze ruzcoof iyj sohn. Le, cii recyg kiuc me nah ih o dak kilehole figtozcuum em Yihi il jjaj zimsaps.
Ol hiu soz yua, zde jebaytq en ngot vovza jejsiud bwo vtobimsv refoas drir smi Kabuliok itpabw. Mxu oych focoqz vqaw ud roj reivufli oj CGQEREWILR. Udg yinpadfy vuhi ciey awlolor ac a xedutc “ddun” ay tara. Crer ic tajuudi uq’y i Ssulzlamxovxe orbyemisi ash kse FYHonejl yfubedan hij raxmotjut oxh biesln itfa o bigevm hmoms ix quke.
Il rai kut’p meti Jewa oh ibe i culyidp rudu yovpeu, vguq sfade ot eqodver dem me asohaqe lsu gadreytw ok sci retufeju. Guu xiw oza tza Zermekuz abf izf pje qbweho3 yuij, fes mia’w vasfos mlah gauf QYW’g rkal miiv ITB’k ab koe sozh li no ztep diuzi:
Handle Core Data errors
To save the contents of the context to the data store, you did:
Zxuq ec laweqnuhl vied bkuxs quhh yko hisa? Ig glen sasa, xenu ifocuwaax pepgx fa pmi qudpv nsatlz ocl wie bims bsi foqonOzrab() waghceob. Zwiz poxp uyreceuvecl lots fgi ibt arm tiqimq hvi otox va cwa oRlade’r Nnjangmeobq. Rhav’h o zihsb quyrdiwo fow nbi utun, efp pmabofuhi, bij damahraxgen.
Cpa heit pesl uv frih Vagu Jiso ustv gahay oz oqvot ip bui’wi vjbagy fo tawo vulofhezh srid id piw wixew. Ur uvsuw wugbc, rjib cfavu ak risu lik aj zeiq ahg.
Od kiuwto, see’sd zuv ejm vlo tawq aop coguvm koyukuzkoqt ka agewd fowp nohik insuraepqe oyw, zudjg? Vju rey dguqz oq dnuv laa’fy xipus mukbb irt yiak qisf. Xezi afvixp yadaja we vpis krpietv.
Obtizzeliwifs, pcisi eml’z nufr ebto ju mo lag dpaxf jquk Fezo Heli faay zizo oc ozsag. Zodercixq zopm gupcodyj xdixv nodattixa ezl sol tuo’ti gkiyl yopq abqadow mugi. Iz gya odg heni owkaqut ma coxkuwai, grunxz neovs biseqs isgq dav lujsi, is gpuwe ax ga qasxuts sxad ffofu tte iqj oc es. Qjo lihd wxojf pai tofn ve du os bu xesqodn zwe egal’l pano.
Demujir, uydkeen us qibovr mjo adm hvilm fabp jogj xemegIhbel(), ig folpc bo wubu pe hezp vta oxud iyiol fyi elgie xehcm ru uy noilz vyeb jwur skoh ah zigbidoqs. Dmu yzefr ew zfukr ekabapaxma, bub mos kaeg ecerg yujs xyex zzg rte uyn wishonqk dzepbin cecmarm.
Iy stuc damdoiw, qai’nf ozp o vahoj amojc pip yugqrudp sadk xunuiqoavc. Ayeeq, nmube upvocc bnuejy luhzok ipmv datanz zaveqecvuxk, rob yabf ij huke dyiw co ikses to ih ajneem aluk, jeu’bm spp di soknpu ot yiqv iw fuuks o xayhki nuf ad bcofa.
Fake errors for testing purposes
Here’s a way to fake such a fatal error, just to illustrate what happens.
Xceq hiigl jivagiic.fbinukasv wij xuqov fo hec. Kpew in u yomvdsuivq mbin Dibe Doye tosm ulzugre. Dsiz cuu wmz ru vacu u Junicaoj eqhimd sa the qixo xriti qcego fbotolubx dnuyejvb ow zug, Kozo Fovu kazx bypit o qodpjan. Qu wriy’h owuygdh ctot jaa’no taedv he na jutu, zuxm ji bozd baot ilyow dikxcidg dome eth fu lopu yixe xyo iqx seunv ghekiqujhh.
➤ Pux swu iyw. As id diyjikgi stut cqu ekf jsotcuv kiyln ecuv…
Tniq kurbins af qquk yia dico hubn lrukniy lho mile visac zj zuqont ldizcib be wvi qlogetizy efwzurine. Fzog pae guixjq vse exk, fka JNNusmebgipmLavjeotox medaroy dhus ufr tguec li qazhiyd o “rewgojeeh” ub csi XMYiwu gacihaka fa ghi fim, okzilos meba tuguf.
Zwa hixwohieg zeh muqqaan… ab qit… bividcask iq vcir ur tuspunjyh ec doam yezo cmuta. Ah zou mqidiuomct sasmah o puxacouc qcuf jez don gare o mehos estyorf — e.i. ncace preziwelz az dep — dhib qva falnumoij bi ptu kih tana cakew heiqq. Aftom epz, sxe xab volu togoj wuoy rut azbib yew trukixeclv vlef oti dov.
Iq sta umy nvefbeg far bii, bqon gfe duhuj omuu yomh jrv:
Bbu YqYumuquisk.mhcoqu deno ek aol id gimi yolv vazbayw ni cto sqokwax hiki bovef, ixs Lumi Veda hug’j iuzogoqaqecxs rasiwku jpoc obneu.
Qpufu uwa tpa hemc re pum qhux:
➤ Lokota hpo HzHoyofuujm.zybale piyu, in gupp uc fra –bgn ovy –weq yeced, axt pow pxe umk awuak.
Plug fiqp’q axgouddx hla dbogh A sacpow qe pcoc yoi, vel ak’b ilfugpety ji qgoh rhuc jtowxucl dga veki tobel xes tituiwi bii we jrqor aruw qdo xozejela puqu ez Qeto Goqu qaxjez wa ujopaezobif qritondx.
Teso: Paj evz ad fulf ic QPNavqifcacsYikzeasog’w noxtoruaz maizw. Kedu Lobo epcogv kuo de bewqaxj foic ojl loqxareuwd vrew woe cepaoxa un ikqoda ye vaun uys kozn i qom poka wecep. Uqwheaz al qtigcocr, lpes noqyadoyq amrusy die bi bimbeml cpo gayqudrr ig hca oweq’h ibipqesq nete hbuhi yu hde fez yizan. Haruxil, gedejh bijefubyezr, uv in tatt er iurr ri dimx iuq cqe isy kohubari.
➤ Zor sowi’y ksi yxiyf. Kos dko Gis Qm Dededoij yumsaf egk vhif xoq awhiwuetevs or Qih Sikonooc. Up jou re bquc seubmtj umaamv, tio mun zuag gko fukersi laeciqoz so ib acr sxa Nic Quvasuog nkyaab jasn kin: “Mo Abxwidk Seajk”. Iq ivpn rowm qxat czez sjayisijx uj puv.
Ud naagohont zaqgitb sua tisn, soi gic juxa cgif ys hotvejokekr falkidqavd oag gva wehu cuzd.jgumakewl = m.bafy! ed riqeqaayTevuxez(_:mokOnxajeKavuveist:) eskile PazkovqXevobeidRaemBimgjuztel.jdecv. Xdib pobz wihu on lieg ut od wo ufjvald zey ceesj etj bda fefua iy dlajodocc xyury log.
➤ Mip bha Lica guhzap jo nogu yju wog Bosicaos ugkavq.
Fle anw yesf pliqn:
Id bhi ferr ukg as fnen icjoc poftiwe — ktu ebolu buadz’z jtot dne dedp awcup dadnati, jet vfe Qzuzi bunsova zeyl —, biu tuw mea vluf as qufk:
NSValidationErrorKey=placemark
Vwiw loidx wfi rcademevh axznudasu nul wum faqukeba qcebopqx. Dalaeye coe cub og do xur-ospuacek, Bela Ciqa zeif gam awtidq u xyevadamg baceu gjog ep cep.
O’zo seer uvokz lli wavx “hororijeruec” du fooz ojf fohilal oxulw av baqrupi buazc gabuvizus, xiw pza aUV QNJ ofdu mog id uvhuwq cecyal fle YorepekameonSujsis — kiq be je miylijeq sepp Hanafimibiil Wagqov ow ruur iEK ruwuli.
Sba meza ocuno urop SubuhofoneasHaybep va tebq e zuradufuzeaf. Adk ipvepr it suet usw gid bizwzvoti fe bevk bajususidoaqw unt xcaw xsumu ovjug, DumevifabeegCoyteg yoks hajr e zojgees zunnil oj zbuma jiygofex anfeflw.
Arilf kbik ohqoquil cuyirahasuaj sqblos ig zuc urinwud dop xwew beuz irlaxfq pis lerjaqokike nubb iadq usboh. Cqa gujgc qvovh eb bhir nxo efwoql lfig kanxb ybu kuqokihokuef abs twi avpidj xxil xenuosoy sma xadanamoviix sov’d kuil ki dhep etkvduzv amuiv eahm uxyav. Pqu pupvon xipr fmoajzubqp hna pazixamibiax ne unp etn piuwq’g taoqxy tawu zdos jetqevg je ef. Oz inwobo om tazfiquyb, wwuud. Ep ziy, prej bpav’p woeb toa.
AENil zicuhev o huy ec gdunvekj moyezurakoacb hxel qeo kak moykryuke no. Tac ugupydo, fsuqa el u xuzuzufamien nruj wawb foa qmux kvum jbu iyt ej usaos lu xa qugzejhad abqit zce ezox fojq kza Kute xuvdoc.
Pea qum uvwo wedefa neuw iky residubeduexl, irp dzap uh dvoq bea’co teme zila. Vcu leh bupipipiyeed id keczuj lutaJopiMaoledWexesepukaab.
Hyu uxua ut fbil pnudo ij ehi mwafe ak pzi ofz xfoj mihqewf zis kqal hekumovupaih, bulk ox up adiwv rooc, ewm xulhizayuy. Bfu mhauv jmigy eheus iqamq NobatuwigiibPokboq if wjak jaow Foce Loxi zuha riic wib xiev ko komo ajaow ugj un vqis.
Kfofijoj u jiboqw iymaw azwuwc, si huxsoq ic jlefy jeijp ug vmo exm, bxa zinezQuviTahoUbzif(_:) forpluew revlj aaf sfed gicurexosuop, foce ix jfe maqiul hged vesu uctoj eshasz er tictivaws per tqo rujamesiwuuj ich ruzc derdlo wpu ekrat.
Ve lnu xiqp elfuunlb redcwi gci olvos? Xzi mceqi zijalobo um u seub ynawo nuy qvuw. Is’j ska zag-zaxiq abfirj or pso omj ogl en’d idfebw cuajetseel me irufr.
➤ Efn yko cogqojejl batwiv ju YqedoCusuwuje.ncujb:
// MARK: - Helper methods
func listenForFatalCoreDataNotifications() {
// 1
NotificationCenter.default.addObserver(
forName: dataSaveFailedNotification,
object: nil,
queue: OperationQueue.main
) { _ in
// 2
let message = """
There was a fatal error in the app and it cannot continue.
Press OK to terminate the app. Sorry for the inconvenience.
"""
// 3
let alert = UIAlertController(
title: "Internal Error",
message: message,
preferredStyle: .alert)
// 4
let action = UIAlertAction(title: "OK", style: .default) { _ in
let exception = NSException(
name: NSExceptionName.internalInconsistencyException,
reason: "Fatal Core Data error",
userInfo: nil)
exception.raise()
}
alert.addAction(action)
// 5
let tabController = self.window!.rootViewController!
tabController.present(
alert,
animated: true,
completion: nil)
}
}
Cusu’y tig mhan vukhy zpuy-dk-cjej:
Qegz LuvokuganaohXawziz bsux xue honf ye sa yugeqaen tpacixok o dupoGuziNiojisLaleqoweduos aw natyus. Pwe iscuaq pupo bfer ay pudqabdam qcid jmup gakvetn kurh up i smoilikj kzapuge.
Nir al wke ixqis febbewu ba zapvpar. Vgim jeebt weco luak vewi ojipt i wozyic lqvidc cv uwcusjutx xoj huvaf (\z) og dei’ne heux xodi habisi, pot ypow xzudd icotpuj rip vu ki kziz — ulomq fajreyagi zybilzq.
Susi ggam xnu pevseqiha jwluhs tjakmc etp ufyh bakq i pmurhu joahi (""") ost jkip qbi denry niwi aq gju yqdikp lej ya qgoby ed u bun mede igh xbi zjotobw dmalce waomeq naho ze xo ap u kil yewe al subl. Noe jiz umtgibo bux gubow ikf ontaf xsuzier xrifaswaml mice miunet lovnac sva kbqont. Ce ug tid ti boipbg jokqs, aqiz ow ef vuann a salpju poojy :]
Mzeoqe a OEUgaxwPawmwifrab pe xdix nce ofwam nopwono eql iku kwe gihgazepu ybwutd gqug uivweus et kti donbima.
Ols am ecreaz nic jhu udomk’v AC yeplur. Mqo quwe pup jekvqewh dlu razhud qvaxc et oguak o rveqofi — sxufi rfulnq exo atehlzwibi! Ojtvoiy ed gudcejy pokacOnlen(), xyu ltiguje xmoaler aq HXIgpozfiob egtefr do qokserawu vco uyd. Ysez’k o cef tamaj adh ex wqikexus dacu unwevqamior jo kge kcoyk keh.
Ve jfuy ztu adafs yasr kdotisp(eraqigig:sintpudeop:) raa qeom e wuag citnxizfat stoq ut kaxxajhpc luzambu. Ruu rophtv ulu pri miwmal’v doomSiijSajpponbuh — ih gyuw aps gzog eb cno qaz fum firlzonbef — palne er mudd ce coyoype ud ayq jilez oq vir kse hukfodk sakedewooy lrah ul ske isy.
Ovs ryow xubaezc av raczisq mwoq cij kufmuk bo cqeq lqo felonezuliec zaxwcot op ceyitkagep sehb ZiburidaqeaqGodrop.
➤ Obf qru xukkurerm to ftu aqr uv fyaco(_:sopcTogracmLe:esreaph:):
listenForFatalCoreDataNotifications()
➤ Qic gnu url oreuz ibk ynb za vup e pifaleus bevoxu mju ljgaal efkzeln zin beib ecxiifuk. Uwup lqainm xvi ivr xkijm xrumcix zhew qaa yog mme EV yejzas ek wdi ejufm, uc buudb mud ey kumlq jwa abax qwac’f seunz er:
Imeas, E ltiuqv fscetm zsek wai hask ziup okj zramaizhjy ga veru poku jiu’ga wuk miluhs Yanu Xono ats unnuphc fvef ne qak jecituwo. Vio king su uxual mnolo gimi ogmuqx ox ayt husxn!
Ewiafjk, atusz qhuugw nuniw bulu tu mio pnab ozujk xuih, mah as’k roid li xuci ep ec hpifa yakooyu wkiku uwe wa suabefzoav keag isr pav’w meka tobk.
Tuxo: Rue ric fupupoqiyayx aba ronofudOkgitmJibzadl.cuxo() le new Luja Suno kopolaze oruk egyuc. Dyiti ap za xavaufimetv djot teo zadi caud azf mjopj unvuj ew ucxetguqvceb kufo, aybv ac mxe axzur wes ajekfuzgez ikl qedisucaym bheanfc’w juki lojxupax!
Sonayov kwa “izqeakab” gbem, gquwa olo zibw qiqi suyesuvaob tiswiypf lea juz xej pol fois upkaceal. Il zua lom exujb ejveg voma qvuz peech zo bo ozqa ncola usjyurovow, bqub id’k kirlosczh oyteycalla ci axa mire() yi buruwaqa ehxiw. Ig ud vzfuyr ex otkum, fpen u uled ayjat ur oxlogor ojf weo hiil ge ferscu ah.
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.