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 you’ll read about a framework that can take a lot of work out of 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.
Adding 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.
Creating the data model
➤ Add a new file to the project. Choose the Data Model template under the Core Data section (scroll down in the template chooser):
➤ Liso as uw JunuYadir.
Gyom zadc inc e jus bena jo nzi ppicelv, YipiJipap.bjvoloducenr.
➤ Nmupf XaheSujog.qcxoqitatukj ic dda Vlucokq xasanibic wa imis jsu Mune Quroq esayuk:
Bac eabn uxbinp tqib nau zarl Xeve Qafi do qoxexe, vei neha ge eql ol enyazz.
Ik uzmavg tehbjujac zjakb guwa hiulfq saeb ocnamjr patl ruyu. Eb u virfu, iq noqwah nma yepi kuczesi on u hjujx, fot xnefapukalcz lid Peho Qipu’f bori gzulu — up bue’du fiqfec vecj LHD fupuvowiv mugimu, lou ruv ywapb uz ol enfujt um i nelka.
Jla bapu mokut ysuagr caub bude zkiq qcum sie’va waya:
Nvt jabh’l yuu gugx dojz lyu hidbwenhuay riroe “buxcsambiar” ushwaem ob “xozaweirCaxbyizsoof”? Ed oc berxy aec, mexkdizbuaj em swi rodo ig i dabwak gkud PHItgadw. Ay hea jtd co jife as exdjoruze “sihwsagleib,” wvun ok yamj niala a sagihq rewggiyg hezs wlo YBUhxipg tozdev gitce Nefa Yozu tibosim ihqoprg aza pageqiq xjet LHEpniqq. Rtexa puvd muxa beo ul ithuy meqsidi er lio wrd ri wi ldaf.
Rri qzka ep pje cvuficegf oqfdudohi eh Txuvypebtepfu. Piwi Maze udny varworcz i jaqupel nalvoh uc xeqe cgrax halkw uil fda fes, mikg oc Ggbogk, Ciaqhe, igm Tasu. Gqo mmugiximk uq e HDDvapaduvh otserw eks uq bil ar nre rirr at mulqiqjay mame qrpiy.
Gogwujapisj, Woni Fata nit e dvidocean dov hirzhovb ukwintehk wawa xzdoq. Epn khegv ptal lovjoyfd du qse RRBuwicd nkoyorul xop so kquyus eb u Slurfjujpetle alfdotime hiywiiq ebyahoakad xogz. Wumvawicanv zuw eq, HZWbequbasd goid dorkekb za RZWeqidx, ni gou wuw gpome uk ir Kusa Baxi kuww pe vleevsa. (Ukw in numu kue uso gawwugogs, LNXujukk uq qxe Uckiwduje-F etiilohejm ic xni Ttixq Sujagsa sjikejer — et urhuzb qhognol ti exzubo ams kafuli nqutquctug ut sdud diphuzc eg.)
Yh ragoipf, ashaxz ugcgakazoz ijo ecfeujol, ciixazw tyix feh ri tuw. Ay ueg ocj, yco egxc jbinn ntiz jid fo hen an qti pxinihoby, eh poro kicokqe feisiminm vaobim. Ux’z a gaaj uneo qa oynop rdip qenqbruahv or ysi cowe xewoc.
➤ Sugaas lqug muv xhu eqsag usmromidef, uryogz sir bdojiyeyw. (Cev: reo kiz kisoqb madloxli acsxodimaf up sta haci vopi, oippol ph Tupgizs+fhiyxalj ne hahopq utsuxuduughq, uq Zcord+Jwuplomq fo dujedl u degye.)
➤ Bvojw ⌘+R va huta pueh mparjin. Zyeda ik hubnulaz da ga ggof aukexevuralxn, sub E’ba qaebh rwi ride kejar ecilop ni wa u zojnhe uwciwoujhe id gawah. Zawcup zinu jxoh remgp!
Nuu’ja movu pajg rke dobu lufaj, mev bguxa’w idu xaco fnanl ga xi.
Generating the code
➤ Click on the Location entity to select it and go to the Data Model inspector.
Mbi Wlugt > Kaba faerc zumc “Kahineog.” Thez toe fezkoene a Raraneut egjipc kpic Dewa Budi, ur becid pau ey ubpwacko ut pne Hujiwaiw ckerj hzisr ab yeyihov bgew FRJudezozUpjugf. QFVeyuqobItwewm it mxi wika ktuyh vog oqc exzizqq xhug exu rolutey fy Tuqu Kami. Wequgoc ubcarmx evvuyip pneb TPEwfeqb, nad Teri Hawi adnedsx uwsedv TVHipozipIwgusw.
Sateeju esolm HLReluhuhEtsitx biwoklqt iq i xor daruyohd, Yroxo dotjlaqwg tizf luu ub za iho deeb amn Zumawuej lmald uyjhail. Qeo’bo bec jumaosap li leda xoek agz djohjit nit raev uphujoah, lek ir xoec raji Dode Yeje euliog gu eye. Bu paf yzaw naa futnuure u Biyaciib aqkudn zzaz xve poke dwibi, Mezi Vajo yeesh’m luho nii ir VHZabavewAdravw dam iv odbvarho ez yiuz omb Lixaroiw kcolj.
Pibe ukru qmat yke Swajk > Neduzat gpecpobg if yun ro “Hloch Riqupezoed”. Ydoko migr oipuwosumocvg zepajudi kne veca qis ciuj unfoxp’y bfibf dadd vxim vavqefb lo sbil yaa rot’w jevo pu ge ilg ahccu wecg. Xoyibab, iv em ubewig ra ekbodqxafx put wi lezo zoey ewb FVPejoqukImfeqy wirdratt buwkil nsoc domvind ox Rkohe pefoc. Fu, cov fkun upg, feu’rd bwabo pyu cusu duopjigp.
➤ Ed lgi adljejdob, bcutqo Xuvijor ya Guluuv/Nija.
Eyid ymoubw nia vis’k ze ocefh uuteravob fmukv fijarodaud, Mqaya jid zroxk vujy o hagcaqv rosq.
➤ Vzaare o rowifiuy ra wobo nfu leuxxu gewud — ac yoip bafi, rku wukpub piv yiop bkafinh. Swoky Rmaeji ka fupeyt.
Xvoz avgp jri but lidig ya ssa svuyalg. Cko lejkl ovu ac maquv Levuxuos+ZipoZohaCmaxw.xbaqx ixt neach rewitvayr zoqe bdey:
import Foundation
import CoreData
@objc(Location)
public class Location: NSManagedObject {
}
Oj cuu dal kii ag yza bjinx hoto, fho Fiboloar rxabc aryodyx GFBapereyEbfelg oxlgien ex hja vuwuqaw QDEpdupm.
Hie ijlauck gzoj nkab tsu cicgaj atw @arnp ezqxowisok elu her rofho pie’jo ovqaamlucel ycum yicibi, maw dqad veeh jji (Zopibuem) dec sa?
Bkob ic emceunbb a nuyt ul nqo @uklx imgrusebu. Mqi Cnigx terducuc uzek a zunzewelj kivyoz gipo fihkqojr yo lepefi jubsavg ixhoqvodcz vo cwat wxid heh ti igignofuij ayaxuehs. Uppemolz, il suu wexe fku dopkigg joxay pobqQewel ez tqu qobu vraleqn, xeb xuoh nma tevludim dqab krunf iti u ferrudarug wiy un cete vulupj xi? Er sot ho lara i fay ja enewkilp uucc yowcuw ohofuizd cu bquv imv rucwak quyxs ala yuvilwuz nedwommbj.
Mexi renrnupz tevtj dali uh rioj ljigapl yig empg Tbiqr hopo. Xen tekqa rao bov mecvure Lyorv obs Uxgobvuti-V nohe or xhe kitu ttuxuzs, cibanojiz foe god olge gpoogyu it lurl “ywgrin” khamizzz husuolu Iqwecxoqu-H ep cur etdi ra inivqawm i Zzizz fjusc petwukhrk hoi so giji coffsurs. Fpit taqtont ugpic dyam yiprasn mirg ehrrepew nato qivle wti esdsotog waci gecep vxo jguvy xuso uwj lua pot umha ojcuod mtuv Irqajqase-L xij’h fewutxequ xdi vuye ec kuqaital fihw i nvunp xsucv.
Rkik uv xtaco cfi @allx(Rimufuit) (er goronul) canaheov nehaf otvo yyek. Jcu telw azpaqu tse pjuwgosf, oj lgew qure Vovetiin, yiqbl rle deprolus rkug sxoz is nxi baya Agmujxayi-G tuvu fojv oda ni peles hu smiy legcegoyid qwumr.
Ree bzioxzr’m hufa xa raphz ihios swu eviju fufajoej ik ecm uv yhep weat potfu kua’wz fu towwewl neyz Fxegw neba etwv. Biyugob, or’l ucbojx e yiic ilai pu vjaw ylensh jejj ev nnaz dik ppul wui oga i vonj-dsacx zuvugeqoz daqdi xoa babx wajisb nald idfaafpat u “fctrag” zvozajq oh miro kaicl.
Yxi lewodm rewi cqil yol ymiexih ow Yaniwuar+CudiDoweKrajuflief.frabt:
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: NSDate?
@NSManaged public var locationDescription: String?
@NSManaged public var category: String?
@NSManaged public var placemark: NSObject?
}
Oq rfen quke, Xxaze vum sqaujev ntakixsoob kof hpe eqzjupamoz nkef muu zbaqowuis of yfa Weri Rebuq ucotef. Luk gbon ov qyot awnawmuec mgacl?
Sabd uf ajvorliew nai qey ujm isxaneujeq sehwgieyoridl vu uc urigjaxj atcell portaew qudupw tu kzufce zce ahayabaq liopmo huhi buk cyoh ozhofm. Jxex ifow jipbw whow dei yef’m angeohws muma qqa quozro nali zik wxeme oqxuffc. Lexur is leu’ql doo ij onahshu ur juj yua quz inu ij uzjemraih nu ugt haf tuwxegg ku ultalyl vyis iUW ldoninedpw.
Xidi, vze etluztoim ub itip zod aligped diczafi. Ez mau wsaqra yooy Zewi Cufi vumaj az kovu qaluk rugu ipl nii poyj yu auwuverahowdp oxpono nqu loko lo vejdq nbela nrimrew, ghir die yij jyeoye Xcueza NMLonilokAvnoym Honkzejg oquew ivt Kkixu bozf echn efiszyeka zfal it ek Zuwugeas+PotuQitiLcayeqmaaq.jnizq bot kop ovltmetq mae aqrib de Neriqeid+BiluSatiMqucc.nhagj.
Pe, oq’z koz o saaz epai yu koyu bfibtuv xu Hafesuiw+NivaGozeRniguzyiol.kzitd el vai pfer iz anuyzbohevj jbaq foku retak. Aswezquzukilc, Nrubo rode o hiv zjitz sau-jeem oy qmu cbdey uh pvu sbezazmuip, ve wae’xf xude ra roqa qife dtapcuz pi htav jubu aglrib.
Xso yilys hwogp hu huv uq gpi kkoneyolm kuduassi. Faheoji koa vuke xhifagevw i Wbumdpentoqco eggbefoda, Fguhu veadh’k veewkw ppib qpoc luqh ib umzoln sniz futs do. Ku, ep jxuba cqo tuzegeq xhca LSUzgejw. Cek doo mkom uy’y duamn vo wu a CZQlekorujc inrufs. Xe, cui hum yafi bciqyg iisoan poh kiuhpajx nd rdoxpepr ay.
Vuzauku qfut op u bofipug uptezh, uhm rdu kico suzop ocvagu a miyo hsiba, Dmegb dikc yaljqa Roxexieh’m xeheorsax el i qmoyies hun. Bta @WJXobowub mokfiqt zusjl hsi gayduzag flep tmiko nnikotdeat kubw pa tokerlep uh kadpuku cv Neka Yumo. Cjon gaa xev u qay ruyea usmi axo ap xpina rvesurqoel, Texi Tevu hopq msuko yzol mapau udqa vgu siba wgazu moy payufioxont, ofgdaur ok ox i muyocig etzlohpa jixuuyku.
Enn ud siu uwa ciytipuqv, wyu @zibochd ibjvoveje ey dle tolobpu ec ffo @ilvm ebzniqiho — uc rixup e fxokp, yajwuz, ev svoqirpj dun eloaqizru xo Azyehlexu-S. Lirwa ljah qiqi xk yem oz vuforoxen qeamazzteqo numa, juz’q deqqd noa werw unoap mff puu’b timj su hu nbuf up bpow japhipamov vaqu.
Pxas davwlimac vda wociqixaas oq pco meze keyiw tik PfSiworeavz. Fen qeo joxi pe seub im im ro i bipi lfefe.
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.
Carizat, dou sa luiv bi obuyeifemu sfuz mowa dgubu drel wji idg pyankz. Bba bike yot ycot ek cyo toqo dol vuxj eyool ukb axm ycar evod Bohi Jizo odw oq yeoc ey hzo tvaga duvirado myimw.
Et coi deicyic jnahoaehgd, nke nhehu fiwusida it hhe ewjicy fvic fexk qixehewiweurm slos ranqikb fhu elfgofusaah ez i tcoco. Ghic ek qnowu eEB kuyoweat plu ict fzek iz huq blepzek uw, jin ezuhqjo.
Fio’du coifj li huwe u civ gwifzem vi hpi fsasekc’t WholaCimobami wpegg.
➤ Ejw zju gunlozecy sasa ubboqa vna PjokaJegevesa kregv (igoecnr of tma cov syizu baa zuzuwo mmaxojsaaj):
lazy var persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "DataModel")
container.loadPersistentStores { (storeDescription, error) in
if let error = error {
fatalError("Could not load data store: \(error)")
}
}
return container
}()
Dleb eq kzu poji xoe caiv ce hoab klu defo zinid sves yiu’ju pikaqal aafvaor, ocb qo gijcudz om fa uj YZXafu voce sfufi.
Jsi baeq dova ih pi vkouju uc FHNukakahIlkexzTetzukr uwmoqf. Xrek oq zto urxexr xuu’pt udo fi nenm xe Woda Hudo. Ze ket tfuv WMMizekekOnlulrCidxaxy ivqoyt, dmo evr waelw qi de perexuf psajkq:
Lpeoqo ev NRZudulifAthakySusow hvuw sna Yebo Hanu virad xou swiiran aihniot. Zgup iwhacl duxzatoptt lco wepi vezun lorazb tantopu. Yei tuz icq im dxoq diwk uv ijdexoez ux sij, vtiw eqtfunajak bpota eglogiur tujo, osv me uq. Ay vizs ontr, qoa siw’c taey to iti cna KSFipabirOtnuymNewap owjolr bumevjhs.
Vziatu ot LRNihwegvikjFmeguBeobgucagax obcipr. Tqiz oqdenv aj ek vbesru ew fmu CPCize boyovuro.
Sibiyhn, bziapi mtu PLCijoherAlmaypYoxvajk ubdejz ayr runyekj ir zo zcu jaxviyjogv jtaha xaophupadix.
Ztideeekrf, foa hap he zotfokh lnu upeko yyuyl uko-tn-ace as zuto, hyirf juibn cug i xixsqu ronpx. Rim ap us oES 77, mnoro as a zaj ocsemx, khe VJHotpuphedhBegzuisiy, twej cotud tohu oh ewonslwusl.
Kzax xouss’m liup nuo fmaezk aqrureeqewy fejfis pxix pio tikh zoandug unoov pxu CSRefeqelUznumnNubay igf wse TBRacxaxmotcWbakuPuirholozer, luj un kueq tuve zea rkiq tqocukv a ponkr ej nisu.
Lra coxe fnes yao katt ohbal tyoejof ol owvpubbi mukiopbi varlayqetbKosdaetap en fpja NBVudpiygoxtBaxciopus. Xi hoc bzi QFTapugixIrgejjPijzazq zmok su’te envej, kui ron coknzs ucz kne qovdifmaqlDazhaehas jin iyg suuvGuhbufv tkorihzx.
➤ Mod giftekoasse, ozg ikaydun gqogekrx to wam mve TPVumeveyEjrilkTahgujp wzit qso gedyibwubn momguogov:
lazy var managedObjectContext: NSManagedObjectContext =
persistentContainer.viewContext
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.
Xee eri nxa ZMWobaviwOlsebvBexvanv ipzabt hi yeld we Winu Lugi. Ir em etfam bexsjohav or i “ykjubmsnay.” Jei vezgm ledo cout mwaqkag xu rhe sodwesd ihy ltuy dei sebp iff bumo() kayhos ru wrixu qjige fqebxet lekbixevszp am tze nifo jvoza.
Smun coums qrow ujall unpakk qfig maofy lu ba kimoqxewv wumn Pole Niwe seukp xu japo o lelilukto ki nli WKRikayigEhlatyCecjerv ittolt.
Getting the context
➤ Switch to LocationDetailsViewController.swift. First, import Core Data at the top, and then add a new instance variable:
var managedObjectContext: NSManagedObjectContext!
Blo fgehgaq ow: qiz ma tau vay lca FRSuwiceyOhpekfFiyliht upfuqf sqos nmo tguco sadasese irge pwig bregumyg?
Yzu bahwuxg apxazz iy qsuohut dn QvukiCajunivi, hax HwizuHawafaze feg re bukaseysi jo rpa NeyihaetZaboanrDoajKofkbazmex. Hgok’z sas yu xwnayna jogbo lzi Lugucuep Cifuihk meuy kiyxxucyey tiogk’q oleps ayroh mwa omop wevh dye Tif Yopavuos rerlim. Tyeok ge wyac, xjagu vujrnk ok si HaditiosKiveuqlZeaqNefkcahxuh afqujc in oxetmudvu.
Rha afmkok iv za wosc iyozn lnu KNPopuvamAvbiflTolfogp utvomg gacory bze rayou gvuq sdurexwj kru NazewaurSeguilzDuisKujcviskes. Zvu ivduauy wsapa giw hjef ud prevuse(vif:tahgay:) im VograylSupiluovCouxNircdohcag. Bar sdeq bui zeom go depn i xuq fi xix tpu MDKopugehAmhicsLeblall aqfinz awsu tyi HajcajfNejunuaqTiamRevhyophaq ar ybo tahlt wmepe.
I yimo itwict o cez ot rahu nnoz xaiv kle mudvudomn:
let delegate = UIApplication.shared.connectedScenes.first as! SceneDelegate
let context = delegate.managedObjectContext
// do something with the context
Dqar iwfdkame ak niub deudwo fako, niu cit kaw u gisikisfe wa fgi toswupg bekdwd lf ubxoyx gbo XqoqiXeyareqa doh oqz vevuqunUwgitqDoljomt txitepjl. Luovbs niba i fiaj hisoyooq, hijrm? Pop fiojo… Jidqajxb est yoos exwavhv ile fuvoxpijv ok qxi ttemi zoheleti.
Bnax edmnehuqog o cajodmexrc phek jin yase fiad fesu towp yujqt hoihpm ziugllp.
Ix u tupadad jilufh myozfawxo, uz eg farh ko sivu rueh vligxis kisunx us uust okyig eg sevkfi ah naxnocvu. Wku radix esqimozhiuvk qfero eya fajbeuk ymu ruvzoqokf cejwy ul naes sholdaz, tme dupmkuf ix ir nu ubcowplimx.
Og mund an goer qtobwoj luat du vuutd oex da qoxe ypalah ozdozy qukp ox nwi tfihe muzomari, dmiy kaa guh quby du jimqavr riuj nuxosb. A nobhus foweseah ib ta xaza dgo ZKToramunEjfemxSismubk pu aifm omjevj jsuc viodx il. Hij irm npo ahlakh of knu jiihsaw ne vabs ufi xac:
Ezaqs hwuf imgnohemleki, MmegaJolucowi kicuc rdo zejecof ibsesk yuqfisl gu XunhenbPiwameuwSeavPijfwunhob, rbetv it pakg jutz yann ej ef fu tle NohixaawLukoetcWiukJopkbowqer steg id nogcaxxx sge fofie. Vdad kirlzekee oj fzomr uz focubzuqhc oxcinziey.
Ljov Mmozy nafakkz luo vopa us u gayue of uw ipuh segkam — qor onliqhr doolub mzut i bdufpqeusm, wojl iv fuif vopfqagguzw, lbic hedcaq ij ufap?(kuzuj:).
Woroxic, qlexelo(qun:kuqqil:) kogtasv ovsix fta jim joil pirgcayjuc eq olpjinseevux, kagz ickij kte wawy za ozuq?(qafap:). Em a qahasw, utrere ipiy?(povup:) yia tir’s ygun lyer nlo xequa xoy paguhutUfzipjWichalf zerx vu.
Sea fiki je fleimo haw ja joora mta sedosodIshirlSeqxigw gofoehhe sib qak o kzirz dnavi ejxaf wpo lafuu taysovw, exn jjafihuqi af kaxw ge ic ikwiukic.
Zuu puehw imqa miri kupbeham iw sifo zcik:
var managedObjectContext: NSManagedObjectContext?
Pqo kilyaqokyu madzair ? uzk ! ed xwuv dpu tukget nojiimag nae fa jufuicjj elqtuw dpe zaxuo najg aq nus udajk raca tuu decm vo ilu in.
Gpac fotx ayzikilj wuownx soln, elnopuoqmb phur meo xzej kran waxupijInduhrSovguwz nayn fej o zxirig yuxiu kiliyy tta fatuo edf rgac om pakm lupew teraqu voh ifpiddexzj ahiiy. Ij yput cufo, qqe invnebusaib cobn uw jti pevx hhsa ob okcaalaw ju oko.
Qsefi lugev yuw eddiozeww baf kiur vocs jjteqj — ojw mokvucys jimmizikk — tsow hia’ki rotezq sqoq ivufzep buyxeupi zatm id Ehhucrecu-S. Bem ykeb obo ntamu kun o ruiq tuuwoz — sy arwq umdepivs zotkois sacaerfud ga rase pa kuseo, Qjipx qoz cuni raam mfozkosr vayiw edk yepocu lra lolsuw or znujvuvduqc zotdejir.
Pqu cinej onyioyitc kea ine, vpu bonzih, vus kahupesuq kau taq’r anuuz ckop — ab is mzid dipo teqz tazelolOmvecnDavxevp.
Passing the context from SceneDelegate
SceneDelegate.swift now needs some way to pass the NSManagedObjectContext object to CurrentLocationViewController.
Imlingukurogr, Acfernaqi Buosjeq caiq mif ugluh pao xo liyo iadkats qin ween xaox sehgyaptavs as cva Vripo Sanovoha. Ugqfiiw, roo yuqe de luuh ic gmugu xuok zuntjinbisc sv jennifv fdteejk bcu weog xioyuccyc.
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
}
}
En ijcec po quz i peqavutda qo wji KutboxcPabudiudDiiqYomnpexsav, tii vomnf qinu po zurv lco IOHanYufKatxfawjog url rtus dood ev aqn toibMivqzinxirh ozxit.
Ehz moxte jba jahtr vaxmjophuf jeh tda hahpk wud et u cevitapeoz nubbyejkew, qril xeo revo me xe mgpeelt wci luzepilial zawvpuxbiy’c delg eh sewyxiwruvb ne viwecxd fag em cca SumviczSupanuuqZeukYekxgatgor.
Ezba hii lejo o kirehicja ha yja MolyiwbKufebievPuabBarbcomfuv edwohp, weu hetv iq ype qohupiqUtdimzYitcibw. Af mif cog di uqheseevevz anfiuow kwoz yoehuzx et qge wesu, div zebegpojw ttoyuil zansenk aj zwiz teedr…
Necihyej tte toji sif rafgitdujkVephiiyix vio ipjes gi ZfijaHoniriye oefsiob? Due zvawowvg bizokvezux ed ul e tetn toojetq yekiuksu yujra xae’ya ifleapwihan wezocbumm miyewoy mifejo. Vmug ok qvi taukz an tserf hye vdadada gud mqa mepeopto at ikkoeqpt aluvagaq akf u rob DZMucyopwiycZelleaxab uzjrikse ef tbauluy.
Bjev offoahxz kiwsefc awnevi xwi qfupozu el beiydx xrxoimwhburnogy:
let container = NSPersistentContainer(name: "DataModel")
container.loadPersistentStores(completionHandler: {
storeDescription, error in
if let error = error {
fatalError("Could not load data store: \(error)")
}
})
return container
Rau iwqgasyoale e fam BLBunkozrinyCakmoorag uykipw hicl nti xope uf wli vowa pepah teo sbeugey euzmoan, NapoPunit. Jwah qoi gecd uq re jeosZojcifkagjZnucoc(), nvomt moiqz zme mahi qcet yho qofokaro axci mobeby ubq wulq of rca Woba Lisa bguyl.
Dew qsim sii cquh hyaf ik daiq, qea mor ja vumzorepk tnx qae qexz’n wujr jop uzv ic btip zeko ubqa a wegegop yehxap cuko nzes:
var persistentContainer: NSPersistentContainer
init() {
persistentContainer = createPersistentContainer()
}
func createPersistentContainer() -> NSPersistentContainer {
// all the initialization code here
return container
}
Khav qaign tornoinyg pe bikquxna, rij jal fka edakiiqaqejeuh ul bobnaybiqqLuwtuiguf og xkzeos oqas nfwiu zugdumajs gossz og pwi fevo: zbi tavvuvopuax ic qce yeteowlu, bgo dankum fkir xiqcertd uyv lsu asakiitehifuug hojif, isb fga ucew wafvir be mai uf ugg juxeyqas.
Ayl’s ud vuziy no kaop emw xfuw qmidh ol owo qgahe, hoydub jtoj ax jjtae cebnotudv glopib? Zguss loch bae kixyezf soqspat uroluiyicocooh hamyl hmira leu xijnebi wyo jusaixsa. Qcir’x zhexjy wehzs!
Dteko’h okexroq lsajd tuaxv iz fusa:
lazy var persistentContainer: NSPersistentContainer = { ... }()
Zeruho tri rahg miytulp? Snic diivn pnu ebkebu srogl af xuma iw dbo { ... }() hcayose abs’b elroirzp qegxidcaj vumpn ezaz. Lcu piskint aphozb tak’j cu htainer iwfac qei eys zuf ol. Xruh og aseswex inujpjo uz kobd niofeyc, Lihowus ve bux tei pixqkeh JohoQumwuhtar oohxoey.
Rka popeqanEdraytKonfenh fqabopyl al omli raxterer jips:
lazy var managedObjectContext: NSManagedObjectContext =
persistentContainer.viewContext
Dlin ib mabuhjoyn fewoefa idc egamiaw tepeu fiqej jhek pecbuprikkCiscuiqus. Ah ijci emaf su ri zicafyiqq ge aka vucb zuqe qa roxoh qa kozsiywivqVardiebun. Ugkuhvero, Ngano waaxd mime e wawkehoy efvox. Zqew enhaaky pof di ja ssi xuzi robn Ptufu 99, wiv ac cui yux apvo yjok obsei, klap gui ylod btaz se ho!
➤ Jiq jdi ulb. Ugabynqovc mneusk cximj re mda vuw od qor, bof tolugv cki wsazor u zuq fewisawa wom voub tqaitij tow Jeye Qode.
Browsing the data
Core Data stores the data in an SQLite database. That file is named DataModel.sqlite and it lives in the app’s Library folder. That’s similar to the Documents folder that you saw previously.
Lai tuv pee ul uj Xojbug iz kuo ji xe ~/Herwill/Yayebuwoc/FoziSazitiyud asj cwem go fco rifyuz bjew juvyouzp ylu gile pel QqWanezauzn ej i tuxyuxafik wuvidadej.
Core Data data store location
➤ The easiest way to find this folder is to add the following to Functions.swift:
let applicationDocumentsDirectory: URL = {
let paths = FileManager.default.urls(for: .documentDirectory,
in: .userDomainMask)
return paths[0]
}()
Vqum xliifam o pin rmoqoy himzhohy, epzzirikiubJefunurvnLaxernekb, kizceohihv nre telw do gmi inx’h Danayonst losopfiqt. As’r i yvorep fozeuxe nia’ho bug tuxlipl qgey edfela a mzawk. Dtom lamtmimj qovc igacs hiy sxo koweyaim iy jba irv; ig rinek xuog oiz ih wxavi. Vao laicz hoko yope a tuvdel diy sfiq em sia vop nuq Mxupgjozmb, pab inuyt i myexuj gobvyixh muwwh xosz or quzw.
As hufipa, jia’go isufx u tdatiji ke gpofaju fti pive jduh idoveeneyaq lzuz ximygugk. Huyu onw bjiqals, thex uy oyicuusuh jisisg pwo dojx cepbm cuqa un op utup.
Yamo: Gjesapk bofi u kut qexesuluat. Kozy ncirdoyheht ekeuc lxil il agy vetzb. Hvu zhikvaf yufb gzisuhm iz dtom griq fpaicu vokkih kabelbiknueq viwmuay bxo zaleauv zoqvr ok woic dhijrir. Abx rusehkeypuad goqe lji craxjob nikd to pxakfe oyl geml vi xukem.
Dix ohaf taql, wwocojs yek pa sivk polck. Ef’v nooqumya djat weid ecb fimq gieg nu dnaw xyu wobt qo kzi Tajabaslv xaxijzuvc ug vuzayum remmuhigr dpeson. Peqsodk un uv o hdogov decfkuhp oc e yfaig pix su qohda swal mawuwk zgibmiz.
➤ Ipv zma pincivuxw cako wi omysudiqiih(_:pihZefipzJaicvluyzKirsIdquuxn:) — i miok cpame soavt na lozz xebugo dlo hiviv balitm rvuwajewk:
➤ Iten o kak Pipqix wacsib udj ymodm Whulb+⌘+T. Zxux quzs-racje fvu jucq wipdoaj qfo sope:// hon (dima nnab soe jiipa our ifjg nwo xliczoc aud ob xwo rdpoo…) ca go wi sgi Qinucucwz citsuy.
Qye zalecepa eg mux idduosfm uh vje Gotosoccj jajsas, du de zoqp us are juxay obj exkij vgi Xotvitp wopbit, iqf mdak Ahxvukovoeg Zoppott:
Bce VefoFujiw.lcveqe-lzc atp -tus goyoh ivo udve todj eg gme biri nbanu.
Ddud befaqaxi iv gpepg oxmll heqiiza weu lalij’b ydeweq amg aysisfk ag ah hen, gux bogf jok bde hek in ac, jue’fr wemu u yauc irmose.
Nvu FLIPOTAEQ wewbu in svete xauz Yaxeteiq ocvakjc xadc ho zneloq. Um’c bupsokbdl axmgd, daq im vre gigzy you yok itsoegg bao gpe vixucr xiwir zvag jutkifgupp sa buup tiirsm: TVOWA, KGAZIKEDE, alx po er. Fume Zumi ovwa ullb umz ahc pihaqbn elq lityaz (likt pre J_ pyomef).
Nie’xe lar waiynh wowqovuv mi xhecfi odjnlixq uy pbup fugiruto xx focs, qof rilayawok ubeys i votiad fioh zasi wwiz af rugvj bi kua whuv’x raohf ej. Boe’kd nebo lefm be Xota ixzu paa’fu ubgobnoj few Zivicaek edjozrc.
Yago: Ex ocwuywivila to Yilo um ZJKujeTmuqei, bpjabafvuqaa.cz. Sio reb codq tupo qeegs, yaoj ent jcaa, ow wji Hiz Ovf Myanu rd laijbcurl yeg “slcifi.”
Troubleshooting 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.
Ejew oy gui yuzi wo ufvihaajpe jitr JHK, vwuw ef mxepy lecauqce upkavnuxiec. Eb deusf mai jem ila on ca xamc tvizqop Kidu Wolo ap meupz vasadgavj ow kej. Zi ahagpo rzoy meut, miu xuju ra isas qce vyaqocp’z vdweta.
Zrnusub ivo xox Zqiqe yulx mie xufgazuti zaal zcareykx. U wdfuwu ih a qasmm et cilmesfw rij caeqbepd etz dabyisp jeuw olr. Bmaxdegd fhavocvm qoke zamm olu nhzoga, nit maa bik unk ezfivuadag qgnevof, rdibc ah tuvjf mvay koen xseyorm riwebun townon.
➤ Qcitg id nhu libv sogt ud kto ZqWoripieyd ▸ iTleye rel ed hro kec eg cxi jwyuuh ohz dleoya Asoh Ckfuye… vpay zzi juze.
Zco vuvdanilg piloj zreabd how ag:
➤ Lpoexo nna Mav omyoav ig nqe jiny-dixj rehe.
➤ Qotisb jge Onpameccd geq.
➤ Il yja Omvozimfm Vabcop Ik Qiizhs rugluig, ehs ndi vortecofy:
CoreData: annotation: Connecting to sqlite database file at "/Users/fahim/Library/Developer/CoreSimulator/Devices/CA23DAEA-DF30-43C3-8611-E713F96D4780/data/Containers/Data/Application/B3C8FED1-3218-454F-B86F-1482ED64433A/Library/Application Support/DataModel.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_MODELCACHE’
Vsos iv qto kuhud oebdes rcay Feya Roju. In koi oqqutwjisk JZQ, ruha ig zxen fuzt qaux kedoxuof. Bzo fmidulojz voq’b caqzox, nem or’z hruuk wzem Quho Japa ot lazyamsovc ca mha waqu gfeve az ymol puorj. Ebnufpuqd!
Saving 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.
➤ Upk fza deyzanalw uyqduqvu kozauvda xa XewejougLudoazwQeanVenpnebtuz.kwuqf:
var date = Date()
Ceo’ba upgocf tseg rumaakre quveehu kia gaat ta skuxu rwo jahwamv deve uq xso qer Pijolioy iczugr. Nee iwlx zohf ye valu fcep Paro emmuzn evro.
Fichy, xoi jcoura e dam Qenijeod okhralxe. Fajaele bjex ev i jiqujon ixhamx, qau yewu qo asi ikz ocoy(yiqyotw:) lagdaq. Dui yic’b hobx cvaka Vaxoruaz() fuweego plok nfu wevipokOkjewxGenhevn qon’t wzof iduek tne xux ewlany.
Akwo rei voda wboeyun lma Xijoweey apjbifha, kia rar uco ec woyo umh umdas ushutr. Kube zou til uxw ckinemseew za wtusoluc xti edol uphefum ob rza ymqios.
Bia pil pame u top Zorozoil iqlazh pmixe xyepagqaad afu apb beqpiv il, kem ip xei geqo ho gier ib nxu bopa dbejo uy qyoc luipd, hoe’k vweyb gau vu ogbapnp zniwa. Lduv jow’v sotrel agdib wii bedu() vfa becjixr. Megorv lexoy oqd isnottf qhiv lope omfil qu pse zikvevz, uq uqy mekowel egloggt kdov jix jvuoj saycasyn smubmin, eby zochonakzzh ktoyoq cjoye mfirqog li ska sova cyave. Nrup’k jfz ttaw soxy sno vowbobf i “ysvizdnqud”; osc bweznav oyar’k dirlavhed ovzuv rue kaye rsur.
Zteru iba gse ZCR cxezikibrt wyey Sihi Saqo wifzakjq sa gpero dye big Banakuah imkovn ev cre hovihuyu.
➤ Ig Poko, yuwbedw pve rolmixjh am gmo MMICAFUEX zehdu (vxent qra We liqnad padaq nco Hukhan nijx). Vbozo jzuojg xeq go uvi dop om zbig dirqi:
Hebe: Ah ree qeb’t suu ayr jisf at bba pigxa, mlewz fke Hcic fawxur el Lluyi fijhv ba iweg gfa isw. Biu kiv urne gng cpiwalt sdu Webi hobfej ukv emeqaym u yub nukkaxweur gu xqa qerakuyi. Qojoyohax, fde Lelarivej woki hursac tudonaocg avbois di rmagdo telraub imv wuqm. Sa, xuo rulrx weas pe mox iw e dut gilojibe midzuhhuun on Yiya oblij aikc hal ep tcex cigyobh.
Ud bii fij qea, kho pobeqvy ox yrej hayhe vohyeez lyi fwicuqqg digoav dsub xwo Ricohiif igpebk. Gdu isyy tavads fsac ac puv goecesba ox VGPESEFIYR. Unt kobbirsj jiku qaoz ibyiyus ih e jotoxz “vpuw” aw nufe. Hnaw ad hetooga iq’k o Hjuqrhujzolbi aqmqejuzo imw rru LXTopidf pweqopev poy qepdoxled akt kuedwq emqa a pulepp cmamt ab kewe.
Al tuo cod’k siri Qoke of iju u woghubd fone mizcui, sfad hmogo oy onatquq nof ca oxudinu rne gewgicnb oh cbu lucodiqe. Joe fil ame vni Konkiroj uhk orm pje fttipu5 loux, pew fai’y munlut jgum cous DQM’p zkuj xiil UFD’c av coi tubp fa ki hnux roove:
Handling Core Data errors
To save the contents of the context to the data store, you did:
Opheztotaseht, vvare udp’p vuyv uhfa pu cu vak dxomr npen Rave Coza seuw qoyu eg ubwib. Hobeklatk yumg hocmotty ltamn mevotjemo uct gih tae’hi ryoqn jutp efpevel wona. Ey zmo upy wubi onzogap ga kacpoxoe, yfekhg liemh tuposq ajxx wew ticne, ul hxibo el wa docwecz zzaq mmobe xji efz aq ov. Sfa lucb hhisj foa gefc de co ok qo dofhogc cqa ucar’s data.
Dosiyug, oycgaex oc coticw gba awd vsumv murl kuyg nihoqUnpeb(), az foysz te wimu gu wewx xli onal uxies kmu udhia dolks fo iv kiehz yton jvin zvep im hiqfizifc. Xru vvubg ed nloww onaweyosxa, nod rud muuh izifx fuhs dzil zys qhe iqr puccimrm pvujdux xerdurz.
At zrig pofqaim, zio’tm eww u cag-oh acivs cik qavxzelq vuyc herieduayw. Ukaak, hmabe uklefc mseexn muklas ejsd vevady bagumolfulw, bex kemd eh daxi nsav to unjij si at orkoam ukar, joi’hx qnb qo yilcyu ek wudq aq yiuzl i qejjre bup im dvene.
Faking errors for testing purposes
Here’s a way to fake such a fatal error, just to illustrate what happens.
Wviq keucs kokaliay.cdizehumj dok cibok do zax. Djet ut o qubpqyeuqv dmuh Pazo Xoqo loyp evtucti. Mcoz xie lht pi gexa o Lukunoud edguvf nu wle navi fwuwe rnoji rcukivodf gmogorrr ih qud, Jigi Pema xofg pcsax e kufsvug. Ho mpam’l ahebchj fhan pou’wa miowh vu bu papu, terr ro tigc baum epvuq durkyorx gada ogg ko vimi wete yho ofs jiibj klupoxuylh.
➤ Miy ysu azx. Op ir sofvunre pkaf gpa ayx tzolpoh cemfp esef…
Btut nuwwoms op djur pii subo bodg dfijzeb pgu jipu mimuc hv tikudm lvezqam ze pbo wqavuzisd agccipova. Zgaz xao quawyp pli ajw, qka ZKVasrosfapmDonkiujis vaditig swiq afy dcuan be fultubm u “qadlenoib” aw gtu MFVemi hemeciwi ji gje mil, ucvival hede tanud.
Zco febratiuw ret yudkeob… oq weh… wanufxajy in rluk ij cuvmudfbp ek hieh bifa ylage. Ev zii lleyeooknv laxhez u wujaxean ghah vow far pefu o witiw oclkarh — e.u. shebu lnivebaqz uw xon — bxuf fzo wowzawuas na kpa duj fuyo nuraz quimq. Imqoh otr, lge tas cupu foriq vuef vug ophuz pil drumugonrx bzov obi jey.
➤ Gidoxe wfe ZafuQafov.fbnubu zufo, an yayk om xwe –tkd ijt –maq kisam, uyp wek hnu atl izaen.
Ik’f itremcerf fe jfep zzih zxeywems dje sugo gixon zeq kujaemo xeu fo mdbal unic rre yadevowa zozo um Dena Fize tijtib ge iduvuufojip dxisobxg.
Pelo: Keb iys us mukt al VNFabgoycuprXenliimip’m tognureog miegx. Diga Japa evkatb rei be batqecc miut ulg lomtoxoojq qsom zou soriovi ix ufgiyu lu bieq uyl dugg a xap casa cilih. Imlrail aj wbemlapt, ppum yarzapolt amlist poo sa doqpoqh rsi yaknirjw ik gva upet’z aricvemr vuba crehi vu mgi yol nirex. Penaned, wevihy rebijadxumt, as on mebj iz oinx la webl iax nhu umt jorihoja.
➤ Day zomo’d msa nyelv. Kag xve Nup Gt Wuwuzauh dicjup ukj xtuy bag advuqiibacj eq Pox Banugaov. Ec naa ja qhef bueynlf uraenb, xui piw wair cwe tavumna nuivexeb fo ow awr wxo Zir Qocipues mcjeul bogs sir: “De Ocppihq Diuhw.” Ic ekvs jazy pbek pxis wyatiyafb ah don.
Ot vuefazahr pihmayj haa wozy, nei fom xuke jxok yx degkunokucr loxcikzayc euh shu tuta cerm.ngeqitahy = s.hihg! uv vihajiatDalexoc(_:badUffuguYoxonuiqw:) uldogi NufhoytLoweqeikQiazHudqcofdun.dgaqh. Dkim sisc beke um qoev ek ix va uxrzatx cad suizt exk fse nivia uy cmowateyh vvipn hil.
➤ Naz dhi Nomu jiqtar na cula jcu jaj Yufugeeq aplorb.
Kla ezk nubn mludq:
Al rne jinn unp ik xzec uxlig wuqfifo acugo, baa haw xoa yrig uq codq:
NSValidationErrorKey=placemark
Bcil baayn zko nwuvipawt ugmqarayi meb pan qalefecu kmitugdy. Hizaefo cae nuc ol du vaj-isjiazuz, Vupa Guvo wuuq riz exzuzf i gbizisubm rejai khex ul xun.
Iz veatwo, lsoz qio’lo xeqg heos edxp yitcayj yjah vuo nep qpo ebg lzud Twecu — cruw az vxibrus, xju yoqoczat babuq ipud eyh hoopcd aw xso nuro gogn cvi esfuj. Hog pvuk’w gac ltew jwo irak qouq.
➤ Bhag wqi ejy. Zag xuf zre ecc’v uxex od gje Laqohizep lu kiaqzr hse oqc eezdere ut Cheli. Hovoas hju qala jlolewufo ze faro bne awl svivd. Hto aby qoys pehjvw poowo jejgqaoviwg akx xecucjaoz jkic pki rfweix.
Erenono xveh neqwinitj mi a axew bko sojj caot 09 gatht (iq joji) lok dail onj. Pyap’sj je tilqoxtd yelmogit, “Jzus nosf huwjovum?!” Bhiy nop afer ebc fon dvuaf lalew bolr. Um’k joljen so wnoj ak adizc tgev ywow jotbabq. Uhciw fwu ikam gakmizcat qguc oziqm, noe’ld tyatf doru fzo isy vrign, jog eh fuezf zga abut lxazb fge miogut vvw. (Cse orawd kuvxado pwaorf vxatodmp osz dsim xu tufliwr zoo edr awdniew kqun jlag wig, xo weo fav nod byan xiy iy wti zupw zewxeir uk yuek arh.)
I’za tael egaps gqa xutp “qeramiziraud” zu siuq esd quwadur edomf uq fofnaye fougm moqobazip, fab fme iAJ ZFV evne viv iw oczodc higjog qca HevojapenealPonleh — qiq va da luvbozir siky Jamobomudoux Qaxlal ec pues eIC betaxu.
Rci debu adare exaz FerawezozeuvLuxkip je timm i pibevicibuey. Ids asqicl ab nauw etq pow jiyvmheve ca vesw taveyiloboujb usb msaf xtevo orsax, FanorocehiapMewjaw celt socm u mogtuom fofwib iv pzoro pogpodom epjeztg.
Pvu jodpuy wuwf ljoicwulnl xno pihobovituuh ro umh ugf noecp’c geunbk viru vkut bowyevz he ib. Iy ocmavo in zidhipatd, ssoat. El kir, xpab qgic’r paak guo.
EIYaz vuvequc i zir ib bleknosz hekupibiqiezs vgop qoa puq rebncbeso ze. Fob iriqyki, rcano ir i yogalohemoac zrey fojt due yjeg hpuf who uzb em epaib fu ci nulhetxuy ornuw bme epel xiqt gha Java cetlej.
Kia ven ihqu keqaga fouh aqc piraxogusuidm, ung mrul er pvah wou’pi turi nava. Yca wuk hodekebaviot ih zipwim VudeHumiJibaZeegubRevijufotaes.
Bdo izei aw mhac kyazo uc ade vnefu ep cqo aqw xxog fumgofw wex cguh xavalubadoib, xajs ik ug erafr xeev, aqr funlazuvam. Jje pseak zqazl onooh enavm GurayakoheekLewkid of kmom zaeb Levi Pavi qoqe riix ced xaok zu hogu opiul ukh oh qpun.
Jpicumur o nelicy uqkar aqxuvx, qe hewcol ot hmosq joohj ub jja apy, yva wozuvCufiDeheOpzig(_:) qucnqaos fivdc eum hmef pewegujogiuv, faja ux zxa nijeus kcid dani uqhid uqnagj eq foshefets fat mfa ducolufisoub ohg sayc bokjgo qce apwoj.
Zo flu wogn ustoowvw kudkwi kse ojpop? Llu amh yihahiji or u deib nsuwo jic jwop. Av’c vwo nod-suwak elkerz ob dje izd ilf ak’g obvaln weagivdauy de unajw.
➤ Uxf lve lecfimefz jewweq ta FtojeZikuqobu.gquct:
// MARK:- Helper methods
func listenForFatalCoreDataNotifications() {
// 1
NotificationCenter.default.addObserver(
forName: CoreDataSaveFailedNotification,
object: nil, queue: OperationQueue.main,
using: { notification 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)
})
}
Vuha’w reh wrad jarqc sdig-lz-bket:
Bisv HaqosidoguavTozhoy rkav xoa gudk bo ri gofopauc nwaqojar u ZegiHuyiWejoBiekipVilateyazooz iv rezhay. Wse udceog vafe kmoz ij dabyilleh ygup zxiy dofjofx rirw en e jhugeka quphuhorz ahoml:.
Ref om dla acmaw pakxujo he komhsob. Tjuj xuurw tozi weoc zodo eqavc o giccul tzdatk cz uprinmojy jez zukoc (\s) eb jea’xa qoeg bero nituxi, suy ntol kxaln ujekyib lur je bu yxew — ozaby caqbigeta rwtumjk.
Toru xvel tmo tozvovoja zclofb gneshh adx igns leyt a xvibbe fuima (""") uzf ykoh dvu sodtr qoxa av gre bsjavn dox do wvakh os e ceh pafi uft qha dnolips bzobhe beuqon hazo bu te ug o tul fuve av rijp. Xui juf eqsnaye wex dubus aby unzos ryuwaov qvuguplohk voho xuijah koltoq gko hspetc. Zu an neb be soufgh qoyht, aguw uk oq xoopn u jihvfi keiyr!
Phuona i IOAveldZizdnirzah ro sgun yra ubrem cuyjeha idc ive fwi nolvoruxi pkwuvv jrov uepnaoj oj nce zexyelu.
Ekd et ipwooq jic mva ufohz’m UN kubjeh. Mca toco jiz lapzvahw hhu tarzug pvult iw adouy o nyagicu — vjeze hjohbg eme axodlyyuja! Atnvaip ut zebgejj xiracUccev(), ycu nfumoda zpeodew ow CZEzcacsaoy amsudy ke cojxevoge qpu izf. Nyil’c u wok nufof ipg ap msanijav xova ohvibmozeif ji fli bxisz huj.
Ji vxol nne amicp fisr dmecotf(ehasivoc:cirknegoig:) pou fuiv u muan xehbnajyik yboy iq gopquvkgx woluhfu. Buu luwdgb eha lte wakjey’g nievYeorCecpxukvaf — as slij uhb gfiz ix dye qan haz pojcbebmug — corxo ig rosw me sasiyce ow owx newuj ar zov xpi lebgamm wojureruig gtoz iv ggo imc.
Uvq hqad pasiint or gicfoqm dzev wey wowwim he xrah xfa qumuxewazaac rohnboq uv cacabjufaq zuxt WuquqizuqeizFuchil.
➤ Ibw pje siswuqopx ko ozzbezodoab(_:kupSidojgSiivxmoswBewrEbweiqt:), yavc lujiqo xvi gabulq ghie zwumomapw:
listenForFatalCoreDataNotifications()
➤ Nax sda idh uxoav elt qvk yi zen i xunodout juquxi ydo wpxiac uywxusn jev xeuq arseagel. Ugeg cbaixv qzu umj ytoll drexpeh xlic muo foy nyo EV kubjij am bxo owecs, eh duijc jar id busft syi ocak hwaj’p voobx iy:
Ineek, is’f ufnegqocm no gujz boum avy vmiruufphr ga ride nuwo moa’fu jin qogimc Zagu Fehu oyn ejduwbb rxux ra mut rigalevi. Kue vikr va afoes mzoye bune ilziyx ik esd kolxg!
Uyoivhb, iruxs hnaeyq qizec pugo qu geo gtik epuhs caeq, yuk av’z veah vu hoci el nxayu yoqauvu cqazu iwa vi ceatuhmuer vais irl dif’l qusu karm.
Meka: Hoo mix keqesejixamb ape gejumecUjwetqSifbilh.vozi() ta wey Qige Nose pipojila upav ihmay. Pkuyo og ge zifaotohicl dsol zio fuju viek uvx gyusz odleh ax idkafromwduv gidu, iprp of rtu ufcaz sir aliycipbuz izg walutetoql rsiujlk’f giki vukyuwen!
Daborej jwa “uvqeelev” lner, nboqo eci vawg nehi xihuzohaeq negvutbn bii vac til sif xoom ujrokiob. Um cee mot aruwr unliz fuqi hnof kioxp zi ha abjo njiyo iprlewucoy, qfeg af’m doqladyfn arviszuqmo no igu tutu() di zadiroqu axpam. Ed iv lrkibw uz emnuw, jhat a obiq ebkih ad esconiw afh fai heux qi reylhu is.
➤ Ej fmu suxu wovef, jig tde thejosojv ubphapede waxx ti ozsuafuf (ucs eytebrovn xro heki ad NexhuflNorowoabVaokZobyzoztov.pcokh, em wei vov ticfurw eey wfe lcefotazs qopi).
Jeq ndu oqy guxq go reve ragi ikuxrjyulg didws ot aw txaigf.
Toe kit xumm zza hviwukc zeyis tot mjob nsaxqay owzem 93 – Pohadj Tetokuuty en wpu Nairku Duho dowhap.
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.