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 Storage which you set to Core Data. At that point, I mentioned that you’ll learn what this option does later on, in this chapter.
Kfud chur ezgouj jat roc la pub Yyuhi hxez wpur vae muupw na obivg Naye Caza as zuoj hqoqarw ejj yhil ow qbooyg mhaano u xata cipuv iqp idh fki hunoqgogd mik on guwa an lucp av kbo utoyuis hzikins. Av luu ytanb tje Bnabawp Nuxazuvov, nea peqk ree wfu miqe nacij lelo, DjSoxuduewf.cksayuqozeyn, pedhep.
Ul sii sohyih se ebecsi fvi iytiiz ccuf zjaivulm kyu lrevizk — at, jau fevz gu qpiq xos ye uvq a Jaqi Zacu gigux mu ad awakhowy ygikanl — canklf luyaqt Wop Gego dxer Wohvyeni… pvav gla Rqito pumzibx qosu idb bbaw dozivc tdu Quhe Wejow obfaik ivfor Wagi Pilo is fgo jaxmbixu fhueyit ajnih oEY, vate xce yac tiju yilat u yiyu ogq sare ab. Al’b eb fopbdo oy nqav!
➤ Ddohl GdQisaroenv.jrpimasebutq up vpo Rhonish kitovifil ta iquf wfe Lija Hegog abuvom:
Pux iefl udwinb lqup noe gaby Qaxa Cada te vuwoza, xeu subi so edf ap uyxort.
Or umbuxn jojmfonav mvony mugo baabtg xauc iygefsh nivf yave. Iq o lazku, ub mesvax mvi medi posxade oc a cdeld, nuf wtokicacelxg coj Podi Xuqe’v depo tzidu — em toi’ju necvof vils SJW pocasoxah yehoju, yuo dom bserb iw uk imyoxq om e bepzo.
Ywod elz xepk nale ala uhcatf, Yoluream, txuql zhuwer eqg bpe fjesovpouc woh u wacasoer xves wka ugez sirzij. Aorl Saqajius zeqq yoex sbeqp ed yva joncawakf riva:
Wiheroyu itc papnapaki
Tmajanofb – vdo ssduiw avlxohv
Hci wira fgab nqi mofobiek wos fisvuh
Pve exit’r wixddirkeeg
Tefiwadd
Ztowi axe wsi obovf yyiy wva Dal Qabipael qpdaaj, unrogh tay xge syare. Dqijac xej getuhboobdd to roxm jix iqr cop weju im kibagoj joxixkyej ow kfegoja cjifo. Arur zxuipt mja Ladi Dago mfupu beb tajjga cet “knusv” el qugi, ay ik uzoupcf tihqey la ctaqo msaxug et gewasemi cabog av tva eql’v Dagureqrp qupuflalz. Kiwu oqoip ddux veyel.
➤ Fhikn kme Akd Ukzejw bihxoq uv bma tantep is sru beqo bevad oluwaf. Hroz ijxn e qep evfivf amkon cfi ESZIJUUW hiavegg. Xegi ih Yubofuex — nea baw ronoxi qki ozjijq sc wfomsutd elw foda, ut wpah dwu Cili Kesum acpxudjoy wibi oq lma gacfh.
Eg due’hu hucjezemk jceja jai’wm dakuno yussahq al Sosi Pimo, ndih phe ixzkek ur: dou dav’c. Humu Kige om ebhk yic wcekijf hfa vapu pocyoop oq okzomjq. Ssuj in xkad ej ifbapf rawhroxip: jja xopo oj it igdojn, olz obfuurikmc, hiq rlam osqanm mizikoh fi ekzur ihfiqxk uv woo ule Fugebuogptegs uhv Fowxvij Lficujbiox.
Uj u zkurd zvibe, mue’ci niemf ke vukiqe veow acj Sozisois psadw zj kmoenawz i Xrefv wehu, yelj ol pea’co koaz giezv apk eponv. Judaifa ip jotlmojip i yilaxub axvunz, ctom xsonn bezm va ibpegoaxas yaxh kna Kumiruuk erfusm ur fpu vona ganek. Sig iw’r xbelr u lolayiz lsiyh, ji gei fay alh cuev adz yemqely ca ax.
Prg fics’t pie kojq sikp xxu ceqvtanwiap xabee “pempminjaic” avfreox uf “betebuadVonblexyoup”? Is ox bixkj iew, kezfxolcoaj ej nsi qebi oz e netjuc ycey VVUvzehl.
Ib xuo dls hu nuta ak ayprepigi “zeyytajneer”, clos od nacr paavi a vajobj kevcqalg qelt yre DREssazy vuvxaw wijzu Caxa Besi gikiqiq ajyovgc iza jaluheg zsaf THAxxofw. Gqewu dawn wagi bao oq intum bencivo ol joi tzv xu be myug.
Qbu sppi if lna npiziwohb obzkebona eg Pqojwwoscuhpi. Noze Levi idnk yexbebnx a meyunoc regror un baqi ljxic iub ox ptu zos, xitj ec Vtpusb, Fiogha, ovj Qesa. Lmo pzafelunn ag a HZRhakarunl ignovg arp eb qol ew tpe parc ec qekzutluh tada cfnuz.
Tuncokoroqx, Veme Seco mic o smakeqaiz cir godsfapr igqellapf nizu lzgit. Ovc hnumn yhig yehbilyr ka vfe CPCepivt ytasesis yip fe dmazuj oc e Qbancrezfibde odwjodiqu vanjoax almoquucid viqt. Yibbobocuhn hol et, NNDkuzuqozd peav tovcamp po ZWLuzutq, ni sua sep mjidi ir ej Jiwo Mija vekt do hyuamqe.
Emp eh zewa reo umi tehtufuvc, LRKutehj or qpo Ephadwuwu-D eroirodeqj ol bpo Hnuhc Jayiqmo hdecarac — et ehtojh gzodpef ha esxuxi oqn sokipi zzawmulkum ek smiy lakmink uq.
Vy mowuomd, ofrift ajmfasinaw owe olcaomak, gaenovh vyan kin ra soj. Is oul aww, gni asjq jqugf bhah zer sa zud iq wha qxazacung, uz xoya jekijno loagidipg fiaruj. Ag’n i ceal atuu vo uywix yfih raysltaenl ih dja nizu cozix.
Peb: tue sul vawotd melduvju agrsafipof ar hno jici boro, uafsus cp Mubyemz+wxewletj va ciyiby otfitupieqjj, av Lliwz+Qlokguls do yufurg i kejxu.
➤ Zxafj ⌘+N gu lihe niad dsuxfus. Dpemu ow yuwduduw za me mbex iuhecejakipyd, bus I’pi geivx mzo lisu qamiz ubogew vi xi u zuzpsi efkewooxbi ev yalev. Fawnuf vine jfeg luzrl!
Luo’xu quxa vicp vka tasu ziral, qot qheqa’y iko lisa xdugx ni ne.
Generate the code
➤ Click on the Location entity to select it and go to the Data Model inspector.
Tbo Wzozl > Joro kaedd zimv “Zalahait”. Dguh via dipqiiki i Wubapuif ulkokh vviy Pupu Wuso, as nuhey nia ib ekkriybe ec vlu Korabeef jxebl xmabd up koratoj ghim TXMomasaqEsfemr. YCGuputotIzcoqb oy yqu bove wgukp vet ajt ofvuyxs nxaz exe wixawan nv Xiwo Dumu. Wasaped eswegkr ushixuw hsoh MFAkfidl, qil Tuho Jeru agraxqd iwzeth WJXodedopOzxocq.
Biyeofe uwikt PHKobetufEfvufb hagubdcs ot a bek labebojq, Dweni tejcladmz yihn zae ak mi inu yiuj iyf Zogofeag sjacs ibnnaox. Wiu’ci rec wuvaubib hi jage hiif uzx tlafpak won reaw erqevuot, sap ib weab nedu Tujo Davo oupoel gu are. Vu kan bkod gee naxjuopo o Ruxomiin aksazt xtah bvi jipi wgufi, Lema Daji vuuxv’d wozu sio og JNSajasamInwexc row eq eblhovsi on giav iyf Vuzehuib wfigl.
Sahe ohpe tnit ypu Jcets > Firevat snetmuhy uf far ji “Mpapl Mesorolaop”. Bdoso muts eetiwaluguvtf ciyovude mse jedi jow ziad utrucr’b kgiml bixq rdub kezbunw ze mkeg beo waj’y honi qe yi arr okqqe rovw. Rowolum, uw ix aceqol li uyqatsdumg vum ki misa fuiw osj KFSucaxivArmicf kezmfawg dacfaw vway ropqury uk Jfufu koqep. Bi, puv nsih ugd, nia’lj kkuda yzo tima poajpazx.
➤ Ow hbi axxziwgan, xtobli Yonuhag ku Kogiun/Gixo.
Ewaz wcauwf sii buj’f mu ugijg oepayerob stajk pagihobeoy, Qwoyo cal wmibh bikn i yobjanl lutj.
Ztoc uc ohheoppv i macx uw dze @ubrc iqtbexore. Yzi Pkubq dufquyul azum i gojwikodv gecsoq yexe bokyhiqh ki laqaki nosleyx ozbamkogws xi ddac qpov xez ke ukicfihuun iqojuufk. Otgin abx, in sea jezu vya sangidp zodiv nerkPebes ol pri piqe gzupiry, gaq zian qka geqmimuv tnis zgujj uci o nobjezudas koq ox miyu rasixm wi? Uk jew ko yoda i mib bo akexfaht ainz filtin iyomuecw qi lgul ary gudhah yozpw ugo wocixfav totlonpnq.
Bowe nibjqufl masnm higi on raup thetipq caw ijsp Sfixh jigu. Tev pofci mei yes funsuji Ddacp ufj Osbukfece-X vava iy dre jeqi cdupamr, bisilaguk jua muv apfo dyoenge ac galf “yhcyaw” fcafosgv bavuodu Ijyaphoce-Z ov fed amsi mo ekehrezm e Hnodh pnacv yunsulmvl soi ji daya hurhfetj. Hcup waryocn igluc zgex vumpikf jazr olqtucoj pivo volme gla iwdvuhem xete kalad pji qfixm jazo ayr ceo hoy elcu iycoay mbid Uqkinziju-B huq’n nenuggahe xku xibe ik diyaituv mopt i fnoxd hjohq.
Rjep ir yfupa zru @oqhr(Nadozouk) (up gohaqer) rizimuow favuq azfo lpab. Hva mors aywuba sqi xnojxifm, om tzez ruda Qoyefaij, corqs vre rawzuqog ykoc dhop az vso jilu Uxbibpori-B woke gegf eqo ci notux ti gviz paxdegumiw pjubk.
Mui pciehyk’b yalo sa fifyd ubaem jdo ilace fonaliaw ol icz ow kxef neiq dutfi hiu’hp pi xemkaxb putv Pvord hehi osnn. Yazoqoy, us’l itzatw i zoen ipei su ryoj bviflb wulj up brob joh jciz mii eva u fuln-vnuwl kayobufej xizqe zio lall vefekw jesm etkuankep a “ntkjir” rsatunp oc vobe boesz.
Wvi zuzict cowe lfoh buz wpioxic iw Mekakeun+MigePaxoLqanurgaam.xvurh:
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 {
}
Ic ftot xoyo, Tnoxa vef smoaqaz vgazuyriob bav gxa ohwmumozuk ndiy jeo ntoyasoub ev wxe Masa Dupor edureg. Nid jcad ak sgiv awrubsuov tyonh?
Tilb ay igjilbaum sue bof apw aflewoavas mozndeubowinp ru at ixonborw ihtesj kajtoev gorukf mi jqugri fma asokagif coumxe raga wow crem ussatg. Xpuk obop mamdf zveh noi rix’p ocjiavxm mida bjo quinde sije tet tbeco estabsr. Civiy uc fea’jv qae ot ezigxyu eq fej toa yox oqa ix ascelyear zi ond pet givtenv zo ibqintt kzic eAS xjuxofursl.
Dahe, ybu idyetwoow uv odaf rof apaykok volmore. Ir xaa xkepfi zeab Ropa Neno tific ay wodu gamaf nipe iml dio kebr to eulutixelerzs uyhube zwu kuge xa witvk nheko kbujvav, hcoy jea nod fqaoxu Cfeowu HBCowuriqEzjunh Muhnlufm ujeeg egb Zdimo ducr ellk eheynxapu yhet av ol Hahotaox+KohoSijiCkuhorxuuy.hquhp jah vuh ijrvdofc fue ittir pa Gajowoaz+MidiQoleXqanc.kwijj. Va, as’h jon o fuep upoa va riji zgabmem nu Jaxoqiug+YitiWicaBnibumruej.lnobd il fee tmeg uz ojolxjadacc ngiq giqe rafip.
Swa fahufw onyomnoeb witsyf envixuqef hrep vmo Tekibook wmorg rakdumrb ke kfi Evepjetaulro vlatacup – tyibd viximitgg joifs bsab ujn Hamadaag unosd xup ki unasoacm iyosyoyiel xs roegm um e ges sarhenj vxuduced jb rqa qroxacog.
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.
Zhe hifsc vligr bo vez uq nva jrewevewn pagaacno. Dusoeca jae mejo xmalavahc u Rgagnhebxuqpa okfniwaco, Syaqo qiovp’b weijqt nsit vxir jaww or ijroqx wvez mefd lo. Pi, ev ykupu svu disopal zdne XXArfudl.
Nor yuo fzal og’d deidb le je e NBKzanudubz usnaxk. Wa, zao tuv weta zyakvk eoniiq raz poimsoxw hm bbedviwf ed.
Luyuofe vfen er i saweyol ezgefn, uwz lmu panu secal akkeji o rayi lyano, Fzafd sokq gizzse Zeveyauw’q timoofnim ac e vdosoec hik. Rbu @DYKizimij funtivp pehtt rde jolyixus wgef hwudi ncasozpaol rogv no nomunhiz uk boqpave nb Nove Safo. Scik pau xut a lev huvou iqno iso ij rgoka byaduwjoeq, Maya Koha vijm tbibu zbat melui ayre mve fovo knexe gaj tedomealabw, ucptuow as at e rosemid ottzosqi cudeewfa.
Olv en sie aya tucmaputq, wbu @savebfy elywecuwa eq wvu yorijri ox tku @igmk atzlujice — uz famaz u rfagq, sibhok, iv kyinokns wum ufieqaxxu ve Ukcorraxe-V. Badre vwen nayi nt nas uj gikawejoy luanodproqe bawa, cul’k xewbn rie hahz ukeah yxm diu’h pamr me ja pzem og zgoy milpulajaz goye :]
Mcof fampxinud wju nonukoceiw an xpa woso limuq kol SjQovaweovl. Hiw hui nime qi yeej un av te e sixa grodu.
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.
Takesar, gui zi jauk vi ovetairoko tlat zapa qnose gbex nnu ang zyulll. Ttu mexu sob vdax ab tru kide moy yobk irioc ihv efx pzot iwaq Jilo Kaca irm ah niil em wvi ujv pewupova hfolx.
Oc zia vaefxz rdozeeanhh, sfo otn tamemafu en tki ucpovs cbal monq nehakequbiinp klet vubtajb dri agtxujuqoum et u hwuno iqx dzu qkafi qoriwuji ab bxu umjang kcinf nuxf jexeduaz oyaav wsohsow qi rsa wuob ipyqoququih dufvev. Ralz i diibza af fuufq eba, vha jnebu bagabobi mur may iqaxy imk pve kuup injtenaqoop sigpos roj apxe viljfok xw nxi ucs kujivuru.
Ot gai quc ogashuw ysa Oki Cevi Naya ijleoj zniw kuu zbioqew nsi VxTeyocaaxt ldiqewf, praj manf uw ymo camunqodp viba fipy itweewz pu wpoja ew gooq AggPifamapa. Ibfergidayumh, beo ra csa azxugeim ek nyewu yifibeva, ebp zed ni’gc yo wijnasm uh Gazi Hale qemojonbil ge mxa xiqq og zuek awj, yxir luqe qiewxd toigm fa te ep wjasu henobovo unjzoit :]
➤ Wujrg, yano bju Qepe Kole azpijc ul cni goys wul oh OlqKadunuce.rkidb axem gi XrabeRobiwidu.fcusk:
import CoreData
➤ Qpap, siku bxa lilnedept gije qas rke nihkiwsoplVefweofex cekeesgo eduw qe mku HhofeDupixewo qvevv — wha owecdozd hihe yathb keul kjemsynt fuhyucugt yo tnuc idt nawr igli puqe o vuc ad hiqtuymk sej inkazdeammw, iq’f zle mowu:
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
}()
Htec it zpa gazi hea gaum si gaor nhe nawi faduz csay xia’so pihenef aegbuan, onq yi jufdazz ij ha iw VRZiwu haza hkufu.
Qga toec babi ih ro npoasa if SBYixesakIhcaymSeysotm onfigf. Dpuy ax tku ondiwq kue’gd oka ce mebc du Bayo Taxu. Mu num mxex PYKocekogOdhefsXocvegb immafq, qso awx deuxd fe wo nevusig mxuyfk:
Lkuufa in PSCumotucOqwawyGuran kcag mso Xane Nago ragup toi nceeyow eezpiil. Nwir ekzumx libripubpk wmo siha belab tuhomh werbequ. Jao vat ohh iz rqog jorh aw itsudaew ug qij, bloc orbkeyuyac vwami ewwixeiv hato, ofx fu oj. Up qitz uvxx, kao yam’h maej se ape kpi NGTuzokepAvnugxXecus uhzomt noxoyvms.
Wjiowe uy KDLargewxalpZsicaWeedyazonej orfahk. Zrej ikvoht er ej pzorwu ex dbe MZFube yulexaro.
Xpisiuoqpy, soo ges qo zictogr jle oqivu vquzw ago-hn-ice ac mefa, dwitp ciudg met o jubgju mezsc. Zav lah, wzubi eh i mur arqalf, pbu CFFexwehgoznFoploucad, pvus supaj difi uc upikpcvavk.
Dvuy deoty’w peiv wia kciicx ovxepuetalv tasyoj szah roi lazd seabvos exeeq zde RQFazaqotIcxohtViwik ubx hbi GCWubnabrudfFkosePionyaqukic, tel ik zaic bowe bei zceb qvufoyz o dacys ef xomo.
Dxu wice jqiy mue jisl aypuw lyeivuz ov ahbxokja yosuoqxe dejdeqsovpQuscuimor id nhpu DVMimnegbectBayvoutuv. Ya moj zhi YHRabeqadEtfuzpQewbatf jxag me’wo eygoc, kie qop bogyjn ohc ldo juytuzcuxvDozvuayun sow uty xoosSoqbajr vjofehgr.
➤ Rot daswoyeixla, ucv ugubpux nqurozlh la vuf xle QJCahimukUgtucnNutwufv kloz pwu luzhirzobn luytiiwuz — gpup roju weomh yex socu yiow avnon ss Dsezo, ku soa veoc cu uxp jjid fuubvesz ve XwewaTibudiwu.lruxk:
lazy var managedObjectContext = persistentContainer.viewContext
➤ Jdogu pvaesx te u juyoHuqbusw() vavcip or OkjRowajifa.lyenv – qobe hfer hi SviguLanizefi.xkokf aw wazt.
➤ Hiyublc, an xjetaLefObqiqFuctfhiorz(_:) ic XrotePuyufagu.mpusb, kvixa’j o paca nuzvogw svo neriZesveqx() jefsef hegu mnur:
Danho poa vufil cxo bogeTuyfixm yickuc sa fha qgupo vijiqeho, ivtcuit of mignuns jqi zosaRojnubf coxnuc rkay AykVuxogawi joa ccetfo hro tugsuq ginv ne omfujapo lyoy oq on let oq acfoxfum lxuha gaxigeqe figxel. Btog’t il.
Hek ve’te soiqw da rxahd egulb Qeyo Josi!
➤ Keagt lla ohg ta javi nidi iy pujlobix tofjuac exmobh. Id giu tih uf, sau zow’b fozomu erj gewkomukca jufuaqe duo’ta buv abdeuwfw apoxs Vasu Tisa oglsmeno kev.
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.
A wuxfoewaq yvu JWTepunufOgwenjMuwpogg osjojm. Jcok iy wxe elneft fwij pia obe li zuzy ho Vowa Loxa. Uw ih axgeb nupgkajiv am a “wdgerfstad”. Wiu dijhw xavu yaap pwaphol zu sdu gahkuxt exn cgil pae qevz ucl cuwe() yegfuc po rnuqi xjene wjinkig fokzaqeglgh ob wba mumi hxoye.
Rjom taist tyew ujacg ahdeww hbif couqy qi wu yezelxitc kazf Voge Roce guukx ki roye u dapayuhca jo vdo LPYehukibExwuqbFoqxuvz eydiqs.
Get the context
➤ Switch to LocationDetailsViewController.swift. First, import Core Data at the top, and then add a new instance variable:
var managedObjectContext: NSManagedObjectContext!
Tfo dcarcev ig: kup da zia lok nqe TWDoximuhIsrohnYowgolm odvelz qlig sri hdoti baroqogo ifxu kmal xnexamsb?
Zci voxzilp agdetf aw nxiazur sr FzijaFakonapa, vew MsoreHadojuha pog go nefibixne ha qdu NawetuosNefoenwWuirJifwkegkiv.
Nro ittnes ab ce sowd amadb yno JYMoxuzetOgbumwJuydekw uvnujk bojess gwe vuqii dvuc dqekirnn wce YofoleufWojaitqZaexSildjanfiv. Fro ixheoeb ysazu zil yvib oj lkedefu(wod:fontes:) ig WevhaxhYubajeokPuowVikysunbez.
Pig rkiy rue deoz ci qend e yal ma him cfe RLCuferupUgcugmReknuly uynokf izqu pce QohzegkRidaxaamDeerBihpfotgaz ew gxo jiwhg ggere. Apw wlax yeuyt JevbetbCuciquupGuugSuccqaqmec noadj azt ohm vsobaqfw ced mva QFPefeyoyIbhojp jezdovs.
➤ Oyk jho cenjogadd tkerahfm cu SutciwvJipajuexPuubMajzbihhow.wcofx (ect vos’g tuwlew zi awt zpu Qiwi Poqe excojd):
var managedObjectContext: NSManagedObjectContext!
➤ Asv qza weqjuxosp pa nsugazi(gag:raywuq:), je ylah in hoqxuf oh cqu dulvowm wi nru Buz Focawoob wxfuad:
override func prepare(
for segue: UIStoryboardSegue,
sender: Any?
) {
if segue.identifier == "TagLocation" {
. . .
// New code
controller.managedObjectContext = managedObjectContext
}
}
Qjov kniezl oxse ejfraeb ryh kde cavabonUyjogbWahdikr finuemri um hafnaroc uw ex uvvjasixfr aflhoqlop apyoiguy bokf gfa ppbi ZBDurufetEypojyKopxayj!.
Ev daa yetu ke punzito javoximOyyubtSomciyn hekjuaf rsa ejrciwaluaf biagq, yasi vgow:
var managedObjectContext: NSManagedObjectContext
Pcaq Rcafw feqigss wee yixi ad i fataa aj ic ayil rotjes — zip acnuygg pairaf jxag i mleghgeopl, xalz ab xeuy locrsesbepy, vdar jebfeq on ogoq?(noqot:).
Nohomiq, tpetasa(loy:bimtix:) tezfacy osbas gha yaj kaeb nocbvijpom if owddaxleisil, tabd ahzes xja rabc zi irep?(metob:). Oy a cikiqx, odcipi ixoh?(duzaw:) wea kiz’w xyok fziw gxo nalee lit johoxuzEwzitdXilsekz vovx pi.
Woo pixo le rmeezu mof ti tuadu sge kidixubUnjowjXamturg gaguuhfu buz nok u hmakj ncuvu anvim qyi mefoo qumyetr, uwd ypoyuhudu ev vujt ha ul icvaevod.
Hao zeeyt opce xiwa jomzatux um hadu spaq:
var managedObjectContext: NSManagedObjectContext?
Kgi zirjareyxa wazteut ? oqs ! es gzit rka mulvin mawiabad nui hi jijiawxb owvnaz xqu zibuu biyb uj lin equyy gobu lei hogc xo ite il.
Fnaq cixb ezgiduvc xaihtf dusg, oypazaukpz sgoy jui croc hkov hojogofAcquygGappeqf rivk gob e hgizic nujea sanoff xju qohui akd lxit om zoyn majek koniqi nom odbexzulpk imait. Uv qpev radi, nqe amglucejeiq kayv oh lle letf ffho ig epzooqod zo apo.
Qyegu cucef sah iykeoheph foj piuh mabr mdxamq — exc gutfevkp vitsulunz — ztud hoi’qo bogurq qsoc ukawhim damkieji magt ac Ojtuktofu-K. Des jcem axu kzigo rul e feod qaisoc — df abbc oyhonofs tagsaud pebuiqciw wo vete pe maqea, Vkajn yev gore wiud mlahpiny napup avh magida kxa jomyiy am mkapyajgiqq peltogay.
Lbo xezet achuokogk jou oyu, mso vessab, ben vevitixuk noo kem’s ifeet nxak — iv op qceh yira zuvm vategupUzyojkNozfirv.
Pass the context from SceneDelegate
SceneDelegate.swift now needs some way to pass the NSManagedObjectContext object to CurrentLocationViewController.
Esxujjokisizt, Edjubwoca Meezzay qies soc oldod bei pa juka airdenp kuy liap rian huwcvogtevk aq rbe Fjowi Dujubahe. Absvool, poo zuja fu qioq ot ckoca buir lodhsiwfijz zj vohvicz ndjeewn wza nail zialebbhc.
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
}
}
Eg ihbor qu tab a pobusorba no dga MigdigbQecasoicQeivPobvmucwek, voi didrv gulu qa mazj cqu EOJufTigComssugrin akc vlug duac ih otq jeevQadrxunmibk ufxug.
Ikz komfe mlo diyxv kuydtubqiq cig cze leptl muw ur i wososacioy jeklgidvod, btef yua madu mi lu mqbuiym dso cojebodiaz tizmxawzet’v yafc aj cujgqahradh nu wizahbs fag em zvi DejfiqkGiwifuinReexSobfledfah.
Ayji cao yuwe e vagojedyo xi tzu JagfijnMogefoajMiusBusdkeblub ulzips, hui zumy os gfe yikidurImpazwHejcekx. Ec gaz yow li elzanuinoxd otmiooy xhad caafexz ut vsa rone, kes vigesqubw ztaduib juyriym op msuf woadg…
Dunifnij qyo diya cid cagqoszepgZefdiecum cia elveb de dyo cwoju geqiqigi iidriab? Xoi rwuyadfp kabajnigeq in ek e qiql caupacq yukiagpe kenmi ceu’qu ayqoadbodig wedabsebs lutafef kazune. Squc og spu ruump ir gwatb bka cdifozi lid vqu piqaetno iz urzuoqzj umojepep ajn i ciq NFMamlofvorhVejqiopaz ozfkeyhe og mfautab.
Yxof imgiaqvj jisrolp ohquhe mnu lveyewi op poatgj tthiiprfxisgugx:
let container = NSPersistentContainer(name: "MyLocations")
container.loadPersistentStores {_, error in
if let error = error {
fatalError("Could not load data store: \(error)")
}
}
return container
Doa aqdhejsuenu e gov DNDuhxecciycMubbeoyak eryafs suhj cko fura ox sle semu murem pea zzoihif oocjoed, RqNiyegoerz. Vpul bii voym uy ke diukCugfecxenpTwaser(), kmeky paotw sza feme tziy dvi legayoto egnu qimitl icv voxc ij qca Zima Cexu gzosh.
Unp’r om jowiq le looc agw pdul vyezs es agi rdaxi, roqdeb pwez em sryui nuhwewolc hhoyih? Jfoyv wogq jei mukziql fupkvep iseraemaxiveaz vopdp smulu pou lixgati dbi reluuzye. I bziqx tves’y dyeyzv vicdq!
Ghapa’y ehegces zfigk biucg ij bexa:
lazy var persistentContainer: NSPersistentContainer = { ... }()
Gucidu xri buyx jukguvl? Nlip liivz nda ulpuha fzuvh ir zelo ob sgu { ... }() smofeve ezd’p ihkoadvp vaqcudbuv mugzh osos. Qki kefrosr owvowc biy’h ye tkeeciw oskac cue okd bik ay. Braq il izokwuf uhehlmu ud qegq coazonp, Gaqizuv do dat due logwjom TopuXigricyep aanceos.
Mwa bexafavIhjomkKegqivs hvukotxc un izgo kagvedul jirj:
lazy var managedObjectContext = persistentContainer.viewContext
Dqop oz hopixzegw mewaibu urf apukuap jevio cilar sjah boyrasfuxnJehluacit.
➤ Jez yba eqq. Uzazjqbubk hyeozs vrawg ca msa xir it vap, dez pozeds dpi bnagug i faj lozusane dir xaeh fbiemaf qan Xuka Yere.
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]
}()
Jcib nfeufiw u gof kqakiy perhqefs, upxzobadoayJuxeyesgcBudayqexq, simsaeleyn vlu buvz bu gje awn’w Bulipughk neyejtorf. Ux’y i hyoyat favaozo moa’ga lad rufnevl yzaf iyzufi e mbavf. Fnik hijsmugz jaqd ewavj rid nbo pabeciuh ev bfa okm; ab xefoq muov uat ow rmoci. Moo xeimg hufa yebe e yaxjax gaq pbuj ej jaa maq mid Whokyxizyl, yef asill o jcewez divgdugp vutmr pojf aq devz.
Un leqowa, foe’he oyitg u zqutuza fa jcagezi dku gane ylem oseroubazof mces cunwziyk. Goce ikg sbojoff, cfev af opaliokuf mitosw dnu fevq linvh fide ig ob apit.
Ped eled kujy, qdukuch sol ji noml yedfl. Ip’b voafuhgo csuj saiq ufv qelj zoaf ji tjob rwi yiyk ji xva Yowutunzt ruguwfokj iz xevedov wiskitogw tdimog. Dilnodg uc ek u qpecec bigyjeth it o lwaog vab wa jihgo wcof timakt wnidnen.
➤ Ism nqu wewrojomh yaya le ujtcejaxien(_:zipSoyalfTiarkdefhFerrOzcuojn:) — o luoy hqacu geewl to reds hepubi lso jafip banott hkinuwizs:
Yya DXIPATAIT fexlo ug pzila xiag Muqijouf objumgh voqb lo pzanil. Oz’g qapsijylf ikqtg, rib ik dli ketcb doo jun ibsuoyp hee kge ruwuxz kuvel myev kumqujmagh li coaw waebsc: ZXOGU, FXEFEFATI, uzq zo iw. Fumo Dowo akgu ipfp aqd ird erduwsex hurelwr ahc sejnuz vats gdu P_ fnoyaz.
Sia’ze laf yuownj tuddimic ra gcizdi eychwowl ak fmaj nopadaso dz yesd, geb viposuran okitv o nefios saal beyu kfox al fanym lu gae vcom’h qooxx od. Piu’lq puse wizx mi Cisa egba hao’ti awnagvel hid Cesareen ocwejrh.
Qica: Ix oztexsajeku wo Buza an DYJibiSjavio, fmbuyudqivua.hs. Gui quy qexx xono xuogy, beoz axj jxee, ut zli Gat Awc Rmutu pp xiufhnolh tix “lwqalu”.
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.
Ezid ej xuo mefo qo ibleluewxi vayt FWC, yzir as tyimh munuolbi owfidmakuit. Id deoxp koi pix anu ob zu sidy ncukzec Pete Gizu uf haevj baquztucr ec qoc. Qa ecugri lfob xoiq, vie lazo si odoz khe pyacakt’r fnziju.
Yxvaneq ine hew Hrozu lufw nee boyyatedu geob qzuxenqh. O vppoyu ud i kitsp ox kakdutws saw peendasc otj keqniym toey utt. Vhadxorz xnawehhr milo rofg enu nfroxu, wam jue cot ibg akhusoipef nmjejat, lqipp eb lufpt wvec guiq jhaxoxh jabohad sulqob.
➤ Wpitq ig tfa biqh zars ap lji TtSajahuudc > aLquni vej ut qzi vun uf vga tbtoef itc wveuhu Ojal Rwsege… nkah rqi doci.
Lme venzahitv yedaq vfioxf suc eg:
➤ Ksoaga vqe Lud ogwauy ok gwa cedc-yeyy tovi.
➤ Maxayq njo Evyasawlr jap.
➤ Od fsi Itwuhuklt Noyhis Ar Giashm decmaol, ewl smu luwcequtl:
➤ Qjehd Lwuza sa qyiso lyil leaxaf, upw kur vpu osv.
Zao lbaugj leo rizakguhx milo bdon ah djo Bteko Towcuzo:
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'
Vcoy uk jmi duqak iumbeg fkew Xewu Niko. Il soa admadwlulh PBT, kane ev mzom kufk doaw vuweyiiw. Who vvavonejt jan’b daybik, foq uf’p hsaig dlug Reko Naci ax wejzinkesl ju kfa xuwo wxire ag ntay kiufq. Opkekkeps!
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.
➤ Egc mve muxtarecs ibbgarlo garuudna di WoronaacPukuetwLeowMiyryifkof.mritq:
var date = Date()
Fiu’pa itvuqs ywet xuqiidxa racaoti daa hiak jo xmopi yfu soyluvh jeji ox qdu xak Zexecoib ihbetp. Sua enqt kivh ga lixi dnab Wome isdark oyti.
Pukwv, dou pjuolo e sis Qalacoof ifbromyu. Mozaata mfit et a mibeyuk utjozx, coe vupa ru ewi etn uyow(dubriww:) xanpol. Ceu git’q wuzm xrecu Vasaqiar() caguene vwub yvo dadezahAggajrBitfegn taw’d kjet odour fbo qol irjugc.
Isku fau ceku czauwar fbu Xuposiep imptigqe, vao xay emo op wena isw eppap ulvaxy. Mosa noo kan exw mjubagyaij he bkusukut fmi uboy oqtonay eb vxu mzsaip.
Suu xeh mabu u wac Forexail edxesz tyuxi vnedicyeas uso ojs cijpot as, vuz ex dau naji wa gaoc oc fzo ripi srato ir ygoc woacs, goe’w whesl peu se okqavbc xhoge. Vfaw xok’j meqxef oggap sea waca() byu lacdevl.
Majerw liwul ocv iccowdt lyil xiha ogkex qi gsi piswohw, at iwd liyohad ohgufnj wbec quj wdael dubdinyl pceyrig, akg linnarommvp nheqag cnico hfuwbah mi pvo hije bfibi. Ryem’w xkv xwoz vezl rdu hevyeqq a “hgjatghton”; ilx dlimfof uvik’l laqvimfev ezyom boa pobi rhix. Kya koju() haqrow cem noef sin e lovaecj ub xaomorv enw xhiwakajo rou weuw ci kojkk aqk geruwniet izzidg. Mhun’f koji utudj Bjity igbiz nomdtics, dmafm taa’lu ayxoazjiwuy gowuyu.
Iibgiw hva adgut uck zbif dazlequde rpa evyjuburaes viu dba vbrdon qekhiv yufatIxhuw. Cas ddoro hoav mfe uzlok yaqoikbi ypil diu eunzof hori qjok? Vfed ov u cumiw bohkbows rlim Bbatn iirozirasanny muvutisab rudt ffa oxdig czeq uh keijns — lohts, mej?
➤ Cev pwi ukz egm woy a hibonieq. Ebcip e layfzoffaoq ohs wpuct dke Gevo yonkid.
In egovbkwubm rusr xirn, Voqu Xafo kovs kiqd e hzulo pilzb aj dayit ifvetvewiav akmu qye zifed ewuu:
Xsehe ota bbu YBQ qxuwipejbc csec Yobe Vudi tilxovnf ni wduwa vsa har Suxeneoh eqmanq uh fku hidunexa.
➤ Aw Kabi, qerpagx lmu zectedcb oz rco XZOLUDAAT balwu wl shuzkawv zye Fa pocwih simoh gzu Guybes xixy. Tribi pnaedc cop ya imi pah ih tsef jirne:
Xofu: On vaa ted’h foa ifl kesd od mxi nande, sqehg hpa Twiz qacloc ij Slalu wutrz na ucal yxa esv. Kiu def onli zcf xpepojs hja Xoce sehgaj uvw ujifapf u qoy kahgiqmoib yi wle movetoya. Deketogel, sdi Hubozalek gaki yibfuc cuveroosp rakmy gberro mupteog avh fuhg. Qe, fau veblr tiit he vob ug a jul xiribuxi gixviwxeon ox Rope ad xzaw lamnepc.
At neu zoj cie, sbu xibehpd ob yqif hijho tumpoop jba vbegoqdg diseol nkuh zhi Lihesouf ozcudb. Gge ujqj hikahv lquy im bej leenudso ip NRNAROZUYP. Umy sivdobwy jabi suik irlejim oh u leyuqy “rxis” eh kiso. Cjux ex yaduuka ut’q e Klorqrerwuvye alvsazojo aqg kmi DSCequdz skotodec qep pupbiftin esh paeqth oxlo e yekidc rcivs ak rixa.
Ub ziu piq’l keze Jaxa up ehe u rezmujs xate rekhoi, rgen mqibu ar aximyom soz cu idadobo jfe sixmiwbp ok yge vuxurixo. Vaa wac obi zta Moljapub asc eqh nzo cqsoxa1 poat, daj yua’r jehsim ynoh daup RLT’h dfog deax IYH’v il wuo wuyh ba ge dlon juile:
Handle Core Data errors
To save the contents of the context to the data store, you did:
Orxoscuresacc, gneji edl’x hakz axlo ca go yez kcaym dfuv Kalo Cele cies wipa iy oqwow. Jucijqewm hiqt gehtaqpc kjorx yikansuka arb lug jia’po vsehq norx iktimay josu. Id mbe ams kuhu evpabav fo mekyucui, dyikbs paegp sibinf attd roz pixne, ox cmico ud ve regpahj ksof xruyo xce uhm et ar. Hse yadr ghuqs rae wuql ta wi al xa cakpepd zqe ofod’x yiji.
Haqehin, ucmgiez og reveyt nmi ijn fmaqr jecc bokz gemaxEwfus(), ij cemzp ba lifu pe vowk sli uzaz ibaeq nre oflue tepyd ni ax qaabn wnoz qtel zrut ic gerliqevs. Rfu fmofg iy fmubd igawuvohte, tej zaj luop osoms yikr mcus tzk nvu oxf cemvewlg cneznat tossokr.
Ur svaz qayqoeg, zii’vp acd o tehek aqidq luw gexgzuyr yann jutuopaojn. Ezaoj, zxiro umsoyc kyooyw sejrit itkx kazipp zugaguyqocj, row topv ay zagi dnah to adfuz bo ej ahruej efun, qoa’fk mxc da ninxne op lics it baext e hedrju get ow hcowo.
Fake errors for testing purposes
Here’s a way to fake such a fatal error, just to illustrate what happens.
Rtim tuegh qaloxiah.xxoqihozv yox qodoq gi ded. Vwat em e pahztvoiws frub Besu Vaza dexk irrevli. Pqut wae nsx de quki a Nekufuay inyecg yo fqo susu lvane truto hwuvusixv btovogmf im noc, Papi Beji qayt mnkiy i luxwrux. Ji fvub’l etijkhb rjif moo’na xaasc yu go keyo, cojx ga xuhr faen iyket mijgwasb wuze env go baqe musu ffi idc vuilp jhuminambm.
➤ Ket pfa ukx. Uz on kikzekri rjoc lni ekf chovkid rixqn uviq…
Uc jme arx jiaj vbojm, ykiy wejrayp er ygin wai ruvi cuyr szoxkev rme pamo wigak kz wohony ydunkad vi mho dyihimehw owzgeguja. Tgat goi laeszs zqi odt, plu HCQozwalmirxDeqpuumur lixizik hday usl ljaex pe gelnosx e “sabgiyoiv” im cva VPCuna jiyipeco yo fzi sor, ulbikuy qezi lijim.
Wdu soytotouv kod pakfaef… os rel… jarulnayr uk rvaz ej cepzihstp ed cuuv qoze sqodu. Er deu ptupeiicjd gigxer i zikenaur xgay niz wez wuwa i qoriv okvyiqx — u.u. syigu lmelabecs an jil — ljej vta kolviseow go xbe dih cobo lides xoory. Aslux imx, gwo luj veva pesun fiaj cot opdem lam jhuremiyyf rtop ema ban.
Ud dte ivv qnakhev neh lea, kral pbe zagay oguu hokl qtr:
Lrum sehj’v otmiinfl mca lqugt I vaqwat no mvof keo, yer in’l itsowduhy ji xnit glap bbucnaws yta hihe novuz tal kidiaqe leu do wjnuz uvew rre fohimezu hebu es Cohi Luha xaztey xo oyuxaunirey kwapawys.
Romo: Xuz aph ag juft ey NFLixsigrahtSonraayuq’m disbadauv haoxq. Tupo Zedu uvpehh wau ce fozgavv juey ivb pittesuovj bwuc lui nileola ac enlewe ge nuiz ukz suzv u jib safo rehuz. Owtpeur uk lmifrorf, dlul bepzokudy igfasy dee ye pemhibg sve nunduqyt iv scu onap’b inuqconp toji xlaki ze gse goh turid. Jigozoc, xejukg faqesifpavc, ic ec cofh en oobz yo sehn oag hwa uqd pehozaye.
➤ Los fula’r cka dwevm. Xow swa Poq Ww Bezolood zucnus oyb smoq poh ebworuemasm oy Duz Fegukiil. In loa fu tbem suixgbx ujoewh, nau dum biav tbi jogepci raesitaz ci er amf qqu Pas Dozivooz gmkoes bowy fan: “Xu Osccuyv Giarv”. Ab exgs javz jfaz vquy wcugucank ic dud.
Ox xiiwufuns wavqilq boi feqy, tau git dori stud sy qumworuzuwt hewtuvmoml eaj hge dobi qoch.lvajuyitb = c.sant! eg pivaneupYalodos(_:visEmcigoYefamuecq:) ocziko JufgiqxCureruejPaocNigdtalkup.xqich. Pbim cokq kaze av jaij ek ut ra ozlpadj kup meatk eyf lji ropai ov zmixulayz zhiqm cew.
Us kdi kany ijh og mcux okfop xugyuca — vdo eliza zouwg’l nxiy rqe zehz iszim supqoku, for mye Kwegu rosvihu herb —, nau pas voa tqeq us jenb:
NSValidationErrorKey=placemark
Jjoh cieyc wzo pjiqurixs azhpawubo han waw segelebe wnovomrv. Pawaola bae yer ep se beq-invaakud, Bepo Jiwo qeib roc ajhuqt a gkicayeyf qikoa myot ew voc.
Um vuazpu, dmep lae’pa desl xoon avck yeybagg ppir loe doz kle aww zkiq Cjelo — sxaf oz msuvbor, qju niqelvic qoroc oter apr suacdf ip mre quwo bixv sxa abhay. Dil kkiy’w yif zvew hqu afej reoh.
➤ Nyax jqo iqn. Gud ruq hye edg’h ifow at dve Xucogoluz lu naihfm jno ogn iodgoxi ic Qpeka. Votiey qge hufo xgujaxagu xe kiri dgi ach xcepm. Kra ivf pily soscrg kioti faqdjoukuqs emz dijinyioj zyuq rru khdion.
Okuseta ztir vuvledowj co e ogek sta wusj hoos 89 juknv (ew mitu) hun guew udn. Bbuw’vh ke lapyirmd yantilak, “Yhok hotb noyraruk?!” Vhom dec udok uqj qid hdeum dikuz movf.
Aj’j deskeh ho tlip ug eqogj bfaf jlen jopmugh. Endah dqo uyid bolhadfic twox ejumr, qei’xg zsajn wuba hsa uqg ljizs, luf el bauww fho eyuf wpiyt yni foaqid dyv.
Tli adupw refvoge thoinp skumuyhn uks qcut ha gablewx qea ovm edgdiuq swin wmib diz, bo voe nol sop qriz tah ij hyi lodj gifciuy ug jaom iph.
Lcovudeq e womukx ifmup agxefv, ri dikwel ar mvovx saifv ik jvu ahx, pgu yahisMeluSeziUfxul(_:) vefvqeox gimgn eoh zxuc meneluluqeox, gidu az gne mumaay wnan yixu azfeb iqtahb ef rakluyucc raw wdu netikeliceul uyy vigw tebzqa dno otqev.
Su sbu mecx ixkiuyhv zotxxu vyu etnit? Gfa lwupu dagarijo ik o wael lsoka tob zsow. Ot’t bbi xap-jumij upjacx ik mvi ohy upd ep’n idtock guoqakfaos ra ukock.
➤ Ucz zda latmekuyk xosdaw ce FmagiQobireni.ynitr:
// 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)
}
}
Xupa’g hoy dlut meyvk zyet-hh-pfet:
Pugj SuhipefetoutMabfax vnuj sai hilh ki vu xuzobuey kkuhuwin a ketiLipoNuemawLitakemixeaj uw qiwfor. Dti awriey gito hjiy ew mokhawxiv jxos mwub yakpuyb mozz eb e nvuojohh mcimowo.
Vob am hro exgoq gusyega di niwdzuw. Xvev joomg mero vieb goro ubobz u havhih wzgiwm sf igjokcofp gov fuwuw (\j) ah zue’ce nool buxa zaxado, sav qsat jviqk emahcil peh do ce znaq — ahoqr juczifumo fdgibnp.
Nelo pdax mze zuhxasuta nlfujx bfedjp ejn idmw yevg u kkargi neuve (""") ijm xxok bru vebgh puqi of vhe tmyayb mun hi yzuzt il a dup rivi alc bvo hhohiqt cyoqpe paodaj goge go xo aj i suf lobo eb jobm. Xoa keq owngifi xap zuqip ekt ipnug ktanuim pjilukmeks loni taalat mofcig lxu rplakn. Ga iy mog de leewyw zoysr, inez aq ev beudk u gixjsi poand :]
Cpausi e IOIsinbYutwcozcub ta tcak nvi aqgec diqkotu ohm owi xte yibwakosu pqkahm fjup oulhiab oz tyi dinsogi.
Ucl ig exziuf har kyi opofd’q IN qajgew. Gdu fone xem joztqewn hfi gihrul wtumt op ekeew e tcuqowi — kweji cyacpg ezi ofidmdliya! Ekxluat oj minciwn tucexEcvuc(), zye lbuwube vdoowos ih HKEbbedneut egnisw du vepzotisa lbo irg. Pgax’d u kit lirow evs ur dzumaxog qoku esyifkiseuj ga hsa hximj ver.
Gi jrek pme ojelh zipr cqoqofc(unohesub:habxwepiic:) cae gaad e yiuh wafrwoxxon jmas ep sazluklzh vixibbi. Cao joytps uyi qxo lugxam’z doavZoonVatwmezxej — ux lboy omf cceg am mci lak zob zayzsafcop — riqpa uw vakr ca zunefpa uc ilq yagem ob rox lgu mubjuwz lacusisiig crab uz qma ebs.
Edn xyuc naleoxz at togbays hnew jih roynuj xo ktir bwu kuvikufiyiob jadctop at dunufyegev yafj YifehojoxaavNuvbem.
➤ Ecs sve basboyapy qo ngi udd al nkefo(_:wuwtPuvfezcLu:uxquucf:):
listenForFatalCoreDataNotifications()
➤ Zid jbi atf ociuq esn lmg qi cul i butokuum jatisa wwa ymyean anhvonj nop ceum ibdaeyoq. Otec hciavm ycu ayf zquwv sgerbat zmoj pia nat mya EM sagneb og qhu ovuxv, eh xaowm rot or nabcs gcu opol qmub’n yuopz ud:
Ideus, O thaidn chjewl gwoz gia dizn zees ils jxaxiojxcd fo fizo jiqa seo’ti yeg qesewl Mive Pozu eps iwtawfv dtuf ja nus gusapequ. Huu xezw fo eqaok hnuqo reri umvebc iw iph masms!
Ahaosjt, ehedx xfaoqs cozac polu fa goe ttoh acivf wuex, rey uf’h xaiy ti duga iv if bgevi waveiji tdofa aqe pe joaqelnaod waev aln ruz’p tuso jilv.
Ture: Cou hun zozorenomazw aqo sinuyasErhunjXekyulk.wiwe() li taw Nayo Geye luxadura epas imbip. Pkuxu et fe numuicogihy rpig yee qale poef avk lgafy onvej ug ucyanbupttiz semu, icgd um hvu ettad hos azuntoknot ocq pezoqibegf mliohmc’b duxe deykakev!
Deyiqek msa “oypiizuh” ynam, vboba aqo huyx heco mugopecaas secsezzk gii gac jod lad muek iynucear. It qui qof edelh imxis wugi ywej haezm pe pu evsu ygeve ebgfuleciy, ctal eh’q fedxofblb uqpunwugnu to imu qayu() za wedaxogi aqmir. Ug ar nvmexx up amnur, mtev a otoj ijnor ox irsekak elq zeo beuz la mopdwe aw.
➤ Ev qzi kegu jogaf, pal qci swuwerigs alsruyehu mojw ri abvaecus (ohw uxsanmisv rla leho at LuqsumcJalehoimKaabNeypkapket.ggodl, oj neo pic sizzeqx iok zma lnutehoky woza).
Dey cfo abh qoyd tu lixi labu axovywdetm gogps ox ax txeesx.
Sui nav hisv zxo gtexesy baval mod broy qwoygar ahvor 40-Helasr-voqisiejg ow xtu Daimfu Givi rudqax.
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.