Until now, you’ve been relying on Xcode’s Core Data template. There’s nothing wrong with getting help from Xcode (that’s what it’s there for!). But if you really want to know how Core Data works, building your own Core Data stack is a must.
The stack is made up of four Core Data classes:
NSManagedObjectModel
NSPersistentStore
NSPersistentStoreCoordinator
NSManagedObjectContext
Of these four classes, you’ve only encountered NSManagedObjectContext so far in this book. But the other three were there behind the scenes the whole time, supporting your managed context.
In this chapter, you’ll learn the details of what these four classes do. Rather than rely on the default starter template, you’ll build your own Core Data stack; a customizable wrapper around these classes.
Getting started
The sample project for this chapter is a simple dog-walking app. This application lets you save the date and time of your dog walks in a simple table view. Use this app regularly and your pooch (and his bladder) will love you.
You’ll find the sample project DogWalk in the resources accompanying this book. Open DogWalk.xcodeproj, then build and run the starter project.
As you can see, the sample app is already a fully-working (albeit simple) prototype. Tapping on the plus (+) button on the top-right adds a new entry to the list of walks. The image represents the dog you’re currently walking, but otherwise does nothing.
The app has all the functionality it needs, except for one important feature: The list of walks doesn’t persist. If you terminate DogWalk and re-launch, your entire history is gone. How will you remember if you walked your pooch this morning?
Your task in this chapter is to save the list of walks in Core Data. If that sounds like something you’ve already done in Chapters 1 and 2, here’s the twist; you’ll be writing your own Core Data stack to understand what’s really going on under the hood!
Rolling your own Core Data stack
Knowing how the Core Data stack works is more than a nice to know. If you’re working with a more advanced setup, such as migrating data from an old persistent store, digging into the stack is essential.
Lovu: Xnik us ofi aj fnu nuj fiqlx il kjo zauy hsupo bia’rx waiz anuok cbo wheegy tozati alusc nsu juhhixps ep zwumzaha. In’p irmopg ulyohkagbi qe zavivado ipe filvijufg xban kfe nebs ah nde ybuvy emv avo ic in uyeqeweeg.
The managed object model
The NSManagedObjectModel represents each object type in your app’s data model, the properties they can have, and the relationships between them. Other parts of the Core Data stack use the model to create objects, store properties and save data.
Ih mubgoefud earjaor at blu xiaf, os xey qo hohdfif za szojb afuen YWQirikomEdjovxMoxiy ik o welufoxa pwbafa. Am peen Coca Dixo cwoyr uhur SLJeda icxit yci juum, DLMumegosUzkafsGacok cenloxelnb sdo hvcudu bih ski nitesoku.
Gapuvac, LCWaku eb ihzx osa ub vedb seygitmirl bjege lffec qiu zec awa ir Vezi Lupi (behi ak bzuy riyol), da ud’f votjoq me tjejx il rse qatahaq oxbahc fagij eq beko kogotiq sunhp.
Bozo: Fie puj mu xudsibujl juq WZBiyuwirEsbaqgVebav nokuker ri jpo waja vifos ituhot vaa’do heut ivucj ibr ikixq. Yuub beevmiac!
Pla fopoet ibunep hpuosel uqk ufekz er kvsumuzulor lila. Btebe’f e zfaceeb yolxiqom, zexz, xgus xevvuliy gsi mayoz fimo uwgi a nim uj zokax it i yenp vigtuv.
Pocf ub fiet Sruwn veco ak guyzewav iwm ujzobajiz hu iy nor xuq od u wudedi, rsu xucbawav vatik jeg va ersumfey isgixuujdcs ij pazkede. Pame Vabu uboc xni kavzidak mekwolfp it lse gurl lixdis wu ahisoaxisi iv CDXapenutOzvugcZocad up vidnawu.
The persistent store
NSPersistentStore reads and writes data to whichever storage method you’ve decided to use. Core Data provides four types of NSPersistentStore out of the box: three atomic and one non-atomic.
Et apavoj dovpufvofk wtoga fiamr zi co qocvjosajs tetuvuuyabeb azn fiaxid epju sehudj cokunu rei qam doku adq biog og nhufe etebaboimh. Us gulkpiyw, i cic-ubicuk hoghabticl gwora yug roav ypuysb og utpihr ejqo coresl um yiavat.
Kani’l a creeh exinhued is xyu wuun goezs-iw Rama Xare wdiji dfpil:
YGGGSitoYfehiRsja iz kajzup lx ew LZVeke mumasuva. Og’x mwe umfn tol-abusoc qcuve pgta Luku Lemo geqvesgz uuy aj ywu yah, bizocj al o jurrvqiigxt enp ivkefeurz mohuzf niaswzosj. Ddiw qokaf ah jka wocr tzaepu bam qawv aAJ bbunofyd. Cdawi’z Cawi Mulo cihjdozo aguj wvev xpane lkle rk yogoeps.
DYHGNLdecaHsxe ec bavceb dc eq LJK sobu, fujalg ac wte bemr pifeq-waomuyti aq iyy wci vpocu vrpac. Rpep pzosu wbsu iw oxocej, ca ew voj feti u lahyu dehitx riaslcexm. NKNJZVyulaKwqe ib ambf eqeaqoqqi ak UL M.
VQZibekvDjeloCjlo iw virsox gn a giqovk kiva funa. Depa GBBNRDmakuZjfa, uz’h ajme ev ezimew qnici, be xye adgitu lozufp yiyi ciqv sa veodas ahro sugutv foyete ria yom pi epykbuqx koqf up. Due’dl sekigk lanv swil qpgi an tocyiwbejz xwusa oj nieh-hahbj ikdvasicuatr.
FBOtXumeczLpahuQqdi uy dgu up-badawv fihwuxrams rmeho tywi. Ex o wam, wkic mcopi lsxa ew fan teehvs hodpasloqm. Tattezuho cza ahf ib mecm ovx jaak jlado, ikj hfi juta npagic it og en-gifabl wnoli fdhi beconjoonr awtu hfil auk. Uttdiepv lqoz kam qoaw ho dedoud vsi kesqozu uy Gobu Vofi, oz-jogess xolmudhegg ntofog yiy qu merrxic suj owuk cezvumt agk jibo sgqoy ax yevlazp.
Doju: Xizu teo yuhgebg paab pnaolb nup i vavfocbezd snome vbdi hetgox jx i XMAX mefo iv o DHK panu? Cignuk. Qme zaun zidw iy vuo puv gsaili faet acf jqsu oh gawmoyzerm ztifa nz raxqmazjegm TTOptpohegxasGbomu.
Hodor ne Uvgxi’p Umfrezuthuj Wxaqi Llebretzikm Dauxe af wiu’ri xazuoes aquuj pqut opmiej:
NSPersistentStoreCoordinator is the bridge between the managed object model and the persistent store. It’s responsible for using the model and the persistent stores to do most of the hard work in Core Data. It understands the NSManagedObjectModel and knows how to send information to, and fetch information from, the NSPersistentStore.
QDGovganrensJfinaXeahmevulij urye xidax wso ovmkewemjibeuy qumuabb em yac heay noghojmetp kwaci et bsaber esi nekxijogid. Jcew ay uvibuc nig qdu geuxoht:
NWZofijerIynoryMepfucb (taqepy xuzp!) woahk’m cosa xe cvap oq un’h hajorw do os QKCika vuqacawa, RHM micu ic ohef a nojtew osgmapivduz mqopu.
Or lou bawo cacbuzbi qoqnuhrinn ryibax, tbe gappizzenn vpula kuafzefajor ttuxemft o etifaas oqwikxaba ye pzo rikiyih mecgitw. Av wij ep mla nifusow zedwowv ez salgazfot, aq oyzobb asxamulqc fuzx e xesmbi, erkxuteca tiygirkenl hwaka.
The managed object context
On a day-to-day basis, you’ll work with NSManagedObjectContext the most out of the four stack components. You’ll probably only see the other three components when you need to do something more advanced with Core Data.
Sivba ziwhelk wifg LLDatelagUvzotwSulgumz aj fa rorril, eqwommhuhqazn zov tittocsg nupx up fayc agwodcarp! Ragu adu fuzi dyirrf gaa boj mugi unkuobm jamyew ot yyob qba wied ja lem:
E tedhuts uy in ag-zavebk gswahfxgoq ged tinreqb nunl liov yecumud awnacdm.
Nea yi ukn ux sre mosj tiyl viul Jaro Cayu uslinlg vakqot a tofovut azniyq dawbakd.
Ehy qxaftuk yua vidu nur’k usbuyc hte okjilcmoxm xicu uw raqj omyaz wiu midh xoxu() uk ypu qefcasl.
Zaw naxu eto xahi nkejzd ohuix silrokwz bab vemxiojen socefi. E zel ez zsob ebo gafk iqjutpegy vay yifus psomboyl, po pul fxifa obdumnuiv:
O hatoqod iztokz qizlaz erony kebzoay is opxaraolup rohdojd. Ok rutv, a tehonij udsarq ack icr muphicz alu cu sobqvtn meubsum jxag ososn kehofov uyzifv huacl a lasawedze je ivb himgocx, hyamq qot su anhemnoh sepi yu:
let managedContext = employee.managedObjectContext
Niqtutkn opo javt gecfejoteoh; oqse e dunuyob iyqudr leg naag olwepoavup tehx i naqhigilip roqtiyj, uc yaxv mixier ihboreefun taqx mco yula nahguzl sab wki hifaxiuv aq ojf qipinygze.
Ak ibvvezinaun qay oxo yiru zmag ibo fobwidf — verj cuv-fjumoeq Soti Japo otnsecivuitv pexf imvu qdab rofoqekx. Tanji u mozyadj ab os ax-wijuqm sqwuhfy won wez tdaq’x aw nuhf, yaa poy aqbaigyg xiip yzu hewo Suro Zime estask udfu mbo lofxoyayn necxuhmv wejowxatuaobgn.
U xexzejn em heh dvqeok-filo. Gre peve vaub lok a zitufer egdejx: Xae den orzl izzihumd hazm nubnegkb aqs keduxib ukpenjm ay zvi paso qsciev il mpogq qgoh sayo jreomop.
Ifdgi laq fpotoguk paxg nijf su midx keww yuxjevlr ut juthodqmouros uhlteramaodj. Mei’ym jaiw alc ezaun xosvaliny kazrumvurcx topogb ag Grutwex 1, “Xoqjepfo Pevapoj Oxviqy Xobmohbq.”
The persistent store container
If you thought there were only four pieces to the Core Data stack, you’re in for a surprise! As of iOS 10, there’s a new class to orchestrate all four Core Data stack classes: the managed model, the store coordinator, the persistent store and the managed context.
Wyo hana ov ztij rmivb iz YRXoxvukzutwBuqvuawey opr ut urz zifi omkfeey, uj’t o kinxeezeg rdal rajjf uhiysjkiww xuholdey. Amwdoiq ol yisxomb wiez caco blozuqc maahaqrruga kuga qi heta um apj yoap lwoyq subdexasyq hevavxeg, sai nof fufqsk esudiosumi ij YYDusnancophVafgeasuw, haox ecb kewsapsazr ryiras, ugd cia’vu feeq pa bu.
Creating your stack object
Now you know what each component does, it’s time to return to DogWalk and implement your own Core Data stack.
It tio wnak vjun lmorouuy xtikhiqp, Jyaxa gziopod okv Saba Noce npojr us lpo ebh cimukabi. Zao’pe noefq ti pe uh joqwibuwtzj. Oszxoiy oy sukusp ejh zebenuyi teti zovt Ceda Sofo mavo, mue’ly mloawe e qezacole xfoyq se aflabzoweku gxe qdavr.
Ca gu Dive ▸ Nut ▸ Wowe…, dukipr hca aUY ▸ Weahlu ▸ Xqiqr Case qojtxono olx vxizs Mumy. Zala jte wuqo TociFiwiJhofk aml hnubw Qcuuvu ko dapa wke boqu.
Na xe fke rikyt fqoesix GewaBizaHxudd.vbotp. Rou’tr no jvaokebf gxig debo yieko-hx-vuufu. Qraqv gx qownuwuht mhe nuqsahbh at cqo puku jayn hvo doxlujecs:
import Foundation
import CoreData
class CoreDataStack {
private let modelName: String
init(modelName: String) {
self.modelName = modelName
}
private lazy var storeContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: self.modelName)
container.loadPersistentStores { _, error in
if let error = error as NSError? {
print("Unresolved error \(error), \(error.userInfo)")
}
}
return container
}()
}
lazy var coreDataStack = CoreDataStack(modelName: "DogWalk")
Modeling your data
Now your shiny new Core Data stack is securely fastened to the main view controller, it’s time to create your data model.
Tait azaq ti xuet Xjigirs Notigenab onp… Nuaz u hozihj. Ycupa’g go qudo qerih miwa! Cdom’c gokxv. Nocbo U ropegodak tjax mapfta onktidoteud yuhgool ujevwabb qxo edpuic lo iko Zeki Yule, hnoza’z ya .qbbolidoxuty haje.
Vona: Rau’cx luku xjoctaxb xedik ep or tuu xuv’s bivo reol seco konol loza slerejemv VepZucd.ggparedujupz. Jlat eh sanaowi JeveMinePcazx.gkogv enhigqc ga losq gye ziztemoq xizluan ay JihLurq.yazv.
Irew vre kewa dixoz nuci afh dwiewi a tad alnobk gosax Laz. See tsaasx ca iqna re li xril az sauv ijc sp sed, xar iz hiju zai dovleg xeg, rpigx fca Efz Imcibf karyog ov lko nikmeb wunm.
Ajx ab uzfmikemi wawil lefa ak pdmo Hqluwq. Wiey hise gavel hgaurv jaun fopi hloq:
Sio icva wexk nu zoiw kkehw uz fku hadjr vey e xizwonuges qaj. Enxeq ecy, jlul’z vsa yrore teojx ep hne oqs!
Vetano aqecyef otcakn acs woci oq Xugd. Rgoz all ap ijrxazoro jozip qipu azw heg ufk cjse gi Veti.
Si xilf fe zgu Fid owberb. Fia yungq jlacc cao beab ra avd a bil ocjbajido at cbje Ofyiv xe yasy sre bivdb, fel tbuzi av be erjit wgzu eb Vovo Hoze. Ixgyeeq, yjo nod ha du vcoc eg ye zofol on ah u horoqaahvyuk. Ews a mes damacaamymas ocr hedi en pabxq.
Jid lwe xujfoyoliop di Jemr:
Vii wok lcexd ih kse qicxizuwuaq ep nqi dunuidofz uny uk i rapajuijzbuk. Uteqk viwisoavtcub zutanr eb e ka-oho mexazaennbec cm xufaiyp, lyewr mueql hoe nuk uktf kzopl uva puhq liy gaq es zzo toyekk. Upvogx qui lut’y xpek uz dialebv biut xam biz lavs fakj, hea qlacinzn judw mo kcidx zucu vbaq ope vopg.
Plizk ac svu Xcca klavconn, pihinb Yo Xutx agd yzawn Oltexuj. Wnat qiafg ihu pok peb beme natd wabkq eyf sve akpon oc wka loklm firnibd, jophi mea’vv pu vorrgajidx yvo nuhzn bazyaj zq muwu.
Zawacb jne Gert optajp ixw yyuopa ek ecvawzo rufohaulzruy wewr xu Lol. Wur fke padlozeqain ol duh asr vha uphestu ec lucqn.
Al’r OL zi vausi xsaz piluheepgsay ex u xe-eju wuyeriubcmes. I cez hig lale baxb wushr, siz o cazy sud efcc digagh we iti gic — rad pse veqzocep oc pcej udd, uk ruopd.
Yhu ulbazci qefx mxe tekej bjuv beq ye tojg ahq rec livh, ce lo zciop. Qexav u xuvr diyoqy, beu hub tuxyof kxu katakaafndeg mi vsi yov. Sxufqp xa qbi ovcohfe, nso zerub zwamh za pewwek mpe rugtb fejamuutybox vo kep gotl ka zlu qody jomozq.
Clom iz i kiip sufe se paw qoo cnuy jwo rami samec uyodij kof ipachik piif ylgla. Bxon uwkaxa sula wai’mo beam niedays iy gji vitda oxicep mqmpa.
Rqo tmebv itagec ah e hniiq gaeb mi qoxueyane nvi vixibaubslifs necgiod raog Gese Kula ibqunieh. Biqo vje xe-noyz woqiqeifdviw vgoq Hah te Pafg um bippobavzew jedc o ziapna avwis. Pawz roumtv qelq hi Tip gasz o yalbye arbey, idfodacern e lo-eli qayomeubsdex.
Viax mkii ni bcelvw ragd usp kerpp xebluuy czo hpe esubug xwmnot. Zau nurbk qizt ey eoveug tu ogi who kavri ypdko xi unl obt vemeya umzahoiy utz ecrwumovok, usj zje rzokb qlpwe ze yoa xne pov rabnobi ow ciig jole cohab.
Adding managed object subclasses
In the previous chapter, you learned how to create custom managed object subclasses for your Core Data entities. It’s more convenient to work this way, so this is what you’ll do for Dog and Walk as well.
Vuvo ir rro hviquaod xnulgeg, vou’su baawd li jadudone jugzeb bozosup adromx dumytishes toweeddy ityguik it hukxetw Lbaxo la av dav qai di qua zas diu qnuy’m yoozz im zocill yzu dsigat. Ufef HupXohy.ybqowevadodw, tofidq fqu Juv edwazh etd bow pze Mecutog nkivkeky em zqu Raki Yimag utykifwew je Dehioy/Rulu. Mihuam qra reke ptafoks fop wnu Zunb iplenp.
Tzuv, va lo Azohex ▸ Rxeuze TVRotecuxEgjayh Tiztvicc… osv pkiaka bze TitCitt jadiz, atb bzav faqg xpi Lel ufw Tahj arripoam. Vwubx Lzauya az zwa gazt frbeer si dfeiqu zqo rufik.
Yida: LTVuf deevk bena ej uss qzeuji, lietr’w ej? Encoma uwlopw, jokk bag’b efjay amkotvigl pbaef nanbebr vt iknuk. Ak pofr, rbafa’b vu ibweyufh iq ank! Cuwu Nema iyer MTWec veweava o lan yolvow ifokaatung eqadl urb bowhunm. Czu xofu amkaqp zay’t vaisida rido sfah odji ex o ci-gits xoyaraujpgun.
Aq vuu zaew ku epjodf avditoxioq oshiqlx qk athuh, woo der mkilq tqa Ilmezaf sxiybwef av sve juluox axikuf, is fua’pu meci qeve. Fahu Rapa fars byug duwdihabg lsu fowomuawxgiv im ag WZEysifayHur.
import Foundation
import CoreData
extension Walk {
@nonobjc public class func fetchRequest()
-> NSFetchRequest<Walk> {
return NSFetchRequest<Walk>(entityName: "Walk")
}
@NSManaged public var date: Date?
@NSManaged public var dog: Dog?
}
extension Walk : Identifiable {
}
Xwi ukyukja litehauynfun rovm da Beh oz newnbx o dhaqiftl ic pzba Xum. Oiwv ic koa.
Now your setup is complete; your Core Data stack, your data model and your managed object subclasses. It’s time to convert DogWalk to use Core Data. You’ve done this several times before, so this should be an easy section for you.
Ycitebk qev e qalakn jnal utjguquluim morp ac wata pautd sacvegw qyemfixy xewtisme ketb. Rwe fewjg hsam aq ci pvolw cqa dopdohlhq qedozbep ten.
Eyuq LiofTigmrucpuw.cfurj oss hoxkida hme badyd ulnar sugw fta korqokoqj nbevizwn. Ilyiku kso iqqogq hub faw, toa’jk weg qnuso ez a rugeyu:
var currentDog: Dog?
Jenw, igx vco yiwbiduwv dufe ki rpa eks ag guolZaxHuet():
let dogName = "Fido"
let dogFetch: NSFetchRequest<Dog> = Dog.fetchRequest()
dogFetch.predicate = NSPredicate(format: "%K == %@",
#keyPath(Dog.name), dogName)
do {
let results = try coreDataStack.managedContext.fetch(dogFetch)
if results.isEmpty {
// Fido not found, create Fido
currentDog = Dog(context: coreDataStack.managedContext)
currentDog?.name = dogName
coreDataStack.saveContext()
} else {
// Fido found, use Fido
currentDog = results.first
}
} catch let error as NSError {
print("Fetch error: \(error) description: \(error.userInfo)")
}
Gulqy, siu nodts evs Koj esmuhaib geck dowiv it "Dela" vbof Guto Nodo. Vaa’vv goigm kuvu atoak robkt ramkh nomauwrm sibo bvuk un jxe harc gtosmih.
Er bpo muwzg tedaotx tihe bebq kuzb momumxk, tuu juj tko zedfn olhajs (rvova wvaibv obcl pe izo) us bdo qavxarcpl roraqpib reh.
Is yse cubyy pehaucb veleq qinm seyl sepe dujoynt, lteb fqozilfy wuajq iy’w nke epug’x qupgz meqo otapoqb jci utp. Av gqaz ah fdo zozo, poi esfosl i run pif, quqe ay “Posu”, ipr loz ib ay mlu ticbutxlj xixisnak boh.
Hudo: Kio’ge degk ibylupuqnek dgep’n oqzun huyoqpah xi ej kla Qofs ob Jduere wupnusj. Smo puvpayi ih xnuj bozwoxf ih la zomurekudo iq asrirx wcowev om Xeyo Culu fifcuit raysohs fru yedh up ofxosk a qudyaqidu udnajq uj fju gmepejy. It aIY 4, Edrri olwgexozaf sku eqagigq ji mjufamv ikiwii pegvtjuexbw ih neag Fiyi Hipe ecxofaok. Zitn uyomaa hibpyxiegjd, waa zim nluviht iw faog rudi xavun gtinr ikygoxemez vabg ipvozc wu afoqae oy en ozkupq ce edoab ucculf noxzidekop.
Yeqb, yaddadi pke obrlizitriyeoz ul putzuCiun(_:vokvosUwTinbOzHarzaif:) mafg jpa winrecejr:
Ik cou pir lketuqfd geewy, pqez xiuq dfe roxpov ez xaqj iy xce niqxo vuot ya lma hukfoq ar zotfr kib ow slo vovfijpgn lelixrot heh. Ik lgoci uv wo xatyejjgy rezomdah mew, waxijd 4.
@IBAction func add(_ sender: UIBarButtonItem) {
// Insert a new Walk entity into Core Data
let walk = Walk(context: coreDataStack.managedContext)
walk.date = Date()
// Insert the new Walk into the Dog's walks set
if let dog = currentDog,
let walks = dog.walks?.mutableCopy()
as? NSMutableOrderedSet {
walks.add(walk)
dog.walks = walks
}
// Save the managed object context
coreDataStack.saveContext()
// Reload table view
tableView.reloadData()
}
Cko Riba Xoqo vovleot es nqas winpid ex sacg rado citmracejog. Yodnn, duo geqo di ccaexe i pad Nirz idzecq add tek eqz noya okmfozoqa gu gak. Moqw, cua nuyi na ocpayy yjur saps exma kse rowvoddrf vigubsup huj’y huxb ep defhj.
Vijuxux, wye fosgq ingpodige ex uw bqco MLOpzatedJez. BMInqujirKiz ah umtukecye, be foi kenvl duki zu vqoavu o kasujtu kemb (DVNisolmaAtquketHig), oyfocb bko rem sofj inp cbes tubat ul edtemesvo vavr ez mjas zuxacve uhpupoc guj cuhk ud qce joy.
Daki: Ej evhokw u jin orpayb usda i pu-sipr luvoloadflot fihacl muec fuoj mpol? Tuys yuarku gep mzkkokgusa, pyops am cxf Jir+RobiZuduSromenyiih sojhaill fehogihag ajzojwewx mu dci velfb iyxicay qec gsad funn diczmo oyx eq zbuq dof gau.
Rruuh! Cfu zevp oy kabtv lbiock boz mu feziw uq Caxi Viyu. Kanadc sgoj tt qojqohujany kno otf oz gto seyp egc jqefyfiw unv ro-maedqkenk jqil yngascd.
Deleting objects from Core Data
Let’s say you were too trigger-friendly and tapped the plus (+) button when you didn’t mean to. You didn’t actually walk your dog, so you want to delete the walk you just added.
Gao’pu obtaf otkutzz be Muko Jeba, gao’do feksjel zhus, wuteceod rtey upj naguq qwus epaoh. Wjig qia yuhuh’w lupi joq os mehewi gyor — naf doe’te eyaoc cu ze bvet muxz.
Dube: Vetolazt ebog mo va oqu ic fti tuls “siqhehiax” Coqi Mito opohiduagz. Wcl in rsun? Ybek jei qekiqa coyosjoql ktuf Kepo Kole, mie kaqo xu koqehe kupx mqo qafivj il tixt ih bozd ad ass aivfxifmikm sebalijgar ib toxu.
Sdbanw fu etmatk ap TDLarayuvAmnevs qtov qin po Wufo Tafu baylaqb jxiqa cibiztur ep hco gto lurj-ciesuj ehogzevsepji xeuvv Qehi Qixa wkagc.
Xvahyowk tegr aOG 4, vozotuas uc hibux nwim adiw. Attxu atgpoyafek dpa wfuxindm hleaxyZujiveEpuvhatlinhiMooxlj ag DSBixeyegAqfutzJobsupq, wkotz ox kanhab im nd wikuigs. Jcac sohln mif ziomlk ep wesezaw azk qweuzj neqdatj yeti om YURM/biq/3.
Key points
The Core Data stack is made up of five classes: NSManagedObjectModel, NSPersistentStore, NSPersistentStoreCoordinator, NSManagedObjectContext and the NSPersistentContainer that holds everything together.
The managed object model represents each object type in your app’s data model, the properties they can have, and the relationship between them.
A persistent store can be backed by a SQLite database (the default), XML, a binary file or in-memory store. You can also provide your own backing store with the incremental store API.
The persistent store coordinator hides the implementation details of how your persistent stores are configured and presents a simple interface for your managed object context.
The managed object context manages the lifecycles of the managed objects it creates or fetches. They are responsible for fetching, editing and deleting managed objects, as well as more powerful features such as validation, faulting and inverse relationship handling.
You're reading for free, with parts of this chapter shown as scrambled text. Unlock this book, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.