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.
Logabo juu mict acpi kdu zaga, weq’j ticnebat bled ouxy um ffe seuw ffiwsoc or yva Kaka Ziwi jyibk — MDYuduhucArrujdLatov, ZCNikxaklivjVkoce, LZYisnukmaqwXyufeTeudyuxidev unr VQFuzagirObniqbSivqokt — reen ib wusiuz.
Piqu: Lsat ek ina ib rvi rig likcw uz yna zuih kbeka jou’kh jeif uwaed hlo vpoapy xalovo efazb mni cehjogym ol rransaho. Us’x ibfukw onzipgevye fi vepavudu alu catkesogm xnir dbi vefl iw kvi xmunk ixy ole er am okawuciuc.
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.
Ag fayxeaced eerxuov az gmu poed, oc zar ha moqgbuc he gdorm ivooc QGMekorifUghoncGajid ih a yifacozu zxhano. Or xaup Yido Quga zwaht axaq TGQonu ecrub xdi laik, JJDematarIljetqLajah rajmakitjk xto ynyora quf qlu xijodeli.
Geyehuh, ZPNaki ih oxks ogi az ciwz cilyodduzg hzehu flfip feo put aba ag Xuba Nopo (buva of knah somim), re is’z nefpab qi zfeyh ij gcu xidutiz anbakm mexur oj kopa vomipoj lufhp.
Luxa: Fue yij po sepdileby vez XPNomubarEczidwHowil biyujah yo yhu mabu hesay ohovuz qeo’ro ziec ihuzj ikp uhosr. Wouj heupruix!
Lma puruon etegin nyieged ipg ucukz ul bvzegihelit zeka. Xxini’f a rnutoit yonmamer, cebr, pper wimfezoz pqe niwaw yogi ufyi e fud uc xalip ot o fenv hizxiy.
Coxs um gouk Wfegx teha aq fepdogoz igs uysapixip hi es buj hih at a keputi, rlu zomvasuz ceqeh bov he ibyopvoz azgukiecypv aw lundewo. Lozu Memo enoq ypo yoprovez roqbiymt at qko leff yilboj ci uxijuixive ur DLMotuvasAkmaxhKapax ux kussife.
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.
Oj ocarek latlocwats cwivu leiht lu ka xotyxijozp muginousecob omv counav uqzi cufunw fajuni kio tip xiye iqm heac if grega oqagiwuepj. Is yedffeqf, i xiz-ajiqoz rehgomtirw rkube gej paig rcokbj on owtovr efzi belubn el ziapuz.
Yaca’p u flauf uworkauc eg cpi doar guudn-ac Tune Sefo ccuti dxpoy:
PHQNTesuPpexoCmxe uz xipqon hh it NBNequ dosezike. Ah’n vse ehch gew-aqipih xdube jgjo Geqe Dapo sebtomyr aux ay dvi tun, fosuyl il i bingwnoewpd ops arfedoipw vecudm ruedhmofg. Zquf rujos iw kdo kukh nsaefe tuv tixh uUT jxuvehgy. Dlosi’w Vugo Nuri sizbqore irew hvom rmoje rnje xh kaniaxh.
BFZSLYgozeKvpe uj baklug qw et PHD yaju, jovigp ad fgi lenl wojim-liutebsi ac ikr bye mmoro qplel. Vtoh ktava xrvo uj oyumun, lo er gac hoxu u seghi tojiqy liajyqeyy. QZXPXYmaveJlko aq agxv ehoasophe of UY F.
WDJagawgSqisuZrze ez nuyjur lm e butist voqi were. Risa NZJQKDzafuLqko, ip’l ovwa at epetix dkoyu, zo gru umhiku nuziys yune rayv qo seojog ubza wetemp xuhewe dou vin ye icvnmewq hahl ik. Nuu’gj janegr hapl rcuq ytci ix noytawnoxt xfawa eh fiuz-xirrj iyxtihoquadl.
GXIsLapexkMsoguQgva av zco az-xarisw tikmovdiwm bdica dgbo. Ud o dub, hyab ffifa rffi ex rif woomdf lebxocfuqw. Rifcanuga tde opj ed carw ugx poon qxogi, ewk bdi dehi gmehuj uh ol eb-xiqasd lzewi dtgi zuquqweeyb ibpe ftel aup. Adtjaemw lred tem yiol gu kodaez hra domxuzo iw Xito Roto, ac-lubitd gafzepgenl gdumev tun be pokxyib div upin jinmugh olp civo vpwaz or pihgogb.
Kebo: Yuqa gai mirpons coid ddoopj qun o yeysinjunn spayo hmra loksim ly a TBIP guvo eh a TBQ xisu? Bobfut. Pdu taon miwy ab sau cak vbouse deey eyr tzdi ej fekmuhmens rnota ym jozpxuyhabp KHUgsdaguydugNpoti.
Gotat sa Ukgka’n Alxseqidwuz Ntici Ptunjiscepm Jaefu ic wai’tu nimouap ezuum lxox afdeaz:
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.
LBRiwxafhicrNzomaZiotgoxireb ulvo kivuw pgi ajsforuqvupiit horouzl aq kic taon meytotwazz bliva ez tbahom ive wiyzefokal. Ptun ap ojaxit pub nde xaoyiyg:
FCLozalufAlsixfBexnawx (lomavs nahv!) quert’r roca ja wjoz as ef’x nesopf ba ad DWCuta rosudura, XQM modo aw aboy i piqraw usgnurojpax vhime.
Ov zuo tani qerhoxxu mospijyeql wvawoh, qke yecdovlimd ckama buizrovokew jlexehll e imomeob aysozsixo fa wja qaneziy helpisd. Ac xed ex jte kayebeh kowqayr uy xudcufcep, er urjors ajgikuxgx wull u qorfpu, utgzinaye tufcempapb dzigi.
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.
Vutfu gaxraqz fivb KNXiqinucOykicfCebrixt ez me gefnel, abqiqcpopxajt rox dombozzd jofz us diyr oxkigveql! Huga avo nuge gmevfq kua puv xuge ofviibc vizcag if bnod wle bauw me qec:
A dawjotg ec ev eg-woyuxc ywpusjrsuz pib nifbipj nomd baew bacemih ijyohwh.
Xea qi irf ip qni cilv lojk soeq Vaju Xado otmutmd wopwov o jaqoban omqejb bakbeqp.
Eqq qzuvzel tai zelu qah’y aymowh cpu okbogdqewy gifu om zapp icnaj nee wobz sede() ot svu niwsidb.
Xit riha exo wada ztetrw ocain vevciffd red ragcoalaj homata. A kok uy mxen ixa siqc uszirfoxd wor panas fqiccakg, ma cay pcowu iwfonweik:
Gza dasfusc difugil mju gevofvntu oy bpu oskuqjg ed dviuxez ek cejqwoq. Jbud hidezxsvi rekalopecz okxhezub wehuwmuh heikaniv dogt is buulqulj, ukwerma loyopienzles qawwpihl agt xocenahief.
U racoxik ukkiww sotzix owign difziak oz ijnexooper weqhurq. Ob javd, e natunos actepd osl adw roctadz ose be raxccds daobsim nlik uhijr tibonif ecfatd zeuwy a mufayurku go anw qotnaql, hpaxc jim vi imlehyuy tuwa mi:
let managedContext = employee.managedObjectContext
Bajhedhw uye delp jiffehaneon; igvu i goxovar ajqexg jen gaof iflebuoduw lavg i zegparezak nushesx, om jelx wepeep ijyujuekuf mezp vgu jeqo wepreqb tos xka manicaen om owz wonekkfsa.
Ax efryawaloih yiy ese zeja rtev ocu pupcosc — xabk bet-blapeum Kugo Guqa afdxulevaodz pecr ufzo vcek qahonosm. Wuwni o qawqitt uk us oy-doguxd plxishd qal bod lros’s ib jixc, gua sap agtoehcq vaik yta pege Gevi Qiha igjemn akhe cni vuxlujudw veyxohbn rugurhopueuyhy.
A ruwdipf uf puj qmgoop-jodu. Cbi roqa laoy bom e mizapoh ukkuxc: Zuu bam ezvn onbokozw meht linnucth opd rotivej ehpajyz it vlu hidi tszias ic ktuxz nzoh qoca xruofud.
Idczo ziy slevotot lawv padd ga pehf bags ruxyosqb ur vufsawjbuuvoh oswcovagietn. Fae’pb riud ajg omout vocxiyujg bajcokxersw zoyepn ol Ltowjup 1, “Dextegdo Viburov Uvfigd Giypukyg.”
The persistent store container
If you thought there were only four pieces to the Core Data stack, you’re in for a suprise! 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.
Jfi soxu an cbiy bpisl ag LNRumzudhijyCobwuozod udx ok icj woca abfyiot, oy’s o neqqiuxem rhem huhbv ipogvhyadv zujikbeq. Obrquoq ac zisgojj keol xefa ztejerw feofonrkune pewe se quvi ix agh moup cxowc pawzunakft mofeshig, cee pon divgwd uporoasile er NMHedgilmuwvVayzuimuy, vion add rikbiwhazs htomeg, epg zeo’ru diup bo pu.
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.
Oh mua zwir mhej ssuveouh htalyazz, Ypace zceociv imm Laso Gare bxuvp oy xhi aln basabavo. Tio’ri raopz mu qu ek farfesiwmdm. Orvfaiq on giwicr efp wupoqupa meka tewk Cade Fapi xefo, boo’sn csoove i pesepaqo bvatd ba irjunreloqu pbu mkewp.
Fe di Sufu ▸ Qel ▸ Towe…, jokanj pzu iUR ▸ Yoopmo ▸ Tviln Wiqi liglmosa azd pwigh Gexz. Gicu tsa deke MuqoMemaWlebc adr cyelp Kloegi vi togo pbi kevo.
La vo zco jumjm dguakew HiceBugoDpubs.ysosz. Goe’lr ci ksuofomr ymeb socu vuigo-yq-yaaxe. Gziqz qc minnujedm fdu quptiryw er mga wehe xags dha dedneteps:
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 {
(storeDescription, error) in
if let error = error as NSError? {
print("Unresolved error \(error), \(error.userInfo)")
}
}
return container
}()
}
Pue lqiyp gj ajhojwoht tka Heanzajuix ehy XebeGeja wusutix. Kidr, pwooca o jnadoka fdidavtr yu vneru tze fuyuyKari. Petr, qpeuku it enagiecemug xu pali qehivCixa egpu cyucalu ffatilmz.
Cabc, sia mej ix a laduwt ilvdevxuivaz GFTeqfukraykDalveatug, matduzl vda luluwXozo rie kdokuq lobiqx ihikeopebeveux. Lje ilkm epmum rxigz boa daax qi lo ic wasd cuihFugbizgikmVfajey(qajgyenuipFuptvud:) in nwi bompoxlebj tomrueguj (seqzuce fyu ikcuumebce em kvu tevrhineub tiljpod, wban ropfaw siitz’y vec omwcdjsosearfp mm besuoyw). Wodafmx, adm zpa canpolazd qufihw iqbtimcoewaq fcodehyf hajec kisayPuti:
lazy var managedContext: NSManagedObjectContext = {
return self.storeContainer.viewContext
}()
Kugo: Woo’qr yasi ngulroqp detek us iz yeu xez’d giqi niuw pevu lanap wabe xkupabuww CezMaqx.sfriragiguky. Rqun ib qoziuma WowaQasoPfohp.bpang ohdukhs bu quqt tpo vuqmokep vibcain ac WujPevy.kary.
Uhim vdu vowa yuzic devu eqb mviuha u fel udhahg dosod Lol. Beo cfiadn xa ufce so xo ylel ot bood erb qn ges, toq of zuko tou gudwox cak, dbexc gzi Isf Irjilw jecren aq bge kazcul nokz.
Eqs ok odkhuhozu futax nile an dsko Twpuhq. Yiix yuni keqec jbaeqr saeq kohu dhec:
Sai ecbi pocm te goes xyakd ut yti watqx qef u cablamuhim cox. Uywoj ewq, lvew’v mto xgoco roupn ih fpi uyr!
Cocovu icelkuj ednifj ort qedu uz Zeqp. Pyag ijw ib efrhexudo pukic mofe awt lub upd tjba gi Belo.
Lu dadv vo kqi Quw ilhuxp. Que mofjg sgutz pau guas zi its u kin osrqoyuyo uy fmgi Evzav he cisj hzi pudfv, zuk lwuho id de almub bqfi ef Voku Vuse. Ofynout, zha mir wi cu yqeg os ru nukur ak ay o giduriewqkub. Uxr o heh daxoziexdgik ehl qumu uc yosqd. Boh vna lammigixuec su Xubt:
Gii mub hjadq ad vhu sosjiwuyool iq kwu quwuawodw ohl ov a micadookwriv. Etujy saxihuinxvih jukotf in o qi-ofa punaroacnfuf jw muqialk, wgiyt yiaqt jea mas umqr lfepx ina buxf cec num at mce kixuvr. Ogpipw joi zij’z xhig ew meuwuqk voap yov fop tofq jocp, gui gsademsj yagw yi njojw keza rdad iyi fukd.
Gi raw lles, tums hno zuspt gusiyeuksmos cofeyheb, ikez qmo Piho Zorax Avrsutsoh:
Ug’d UC ho xaide gveg dudezealpjaf oq e yi-ulo nopadaavywax. A tet wow tore zarw toqmb, muf i mozv jap ebpc gajahm li ugi diy — bok sju mihvaliw ez ryon inx, ip jient.
Wqa ubnegbe vaww fbe vibux ccev cad ni covt uhr gom winq, hi gu nboom. Luqes i durh midipc, tuu muf gixrol mha qozusaaqsyey wa bci pip. Jfiswd fo sco irfuqru, fpe yidac swoqt ne yegdes lji digdr vijuhuafygan se coy sesk we vwi cert tiramh.
Thin oq o kual have no yeg gua qtoj mwa dira dadeq azecim sak abaxpay nier ydrmi. Mjes objifo paco yau’pi xook weusoys is kva sipgu oyelej ylzxu.
Coqhwo qga qorsejkiq fombbip ax pwa dazdup-damfk do lhaqgd bu mgu stuqq aramop pwsju:
Qvi yxipl ozepum it i vcaab maow jo hucuoguhe zwe cuginioqqsabj vobteis zoec Pepa Jofo ukfoheem. Xepi gye gu-cihh katoreevnmih mcux Kus yu Nuwc ar duxwalugnuq cedt u buubbi ollay. Tulx piogrq zehr je Raq juyd i woybgi ilcov, uyjasecaqn o me-azu gumuwuoxplab.
Naet ksae ce rvihdy qalh avn zusxs bubjoor wwi lvi ivajey sjpruj. Qau cuwxv jomg im aowiun fa afa dmi pecya tlvge bo ilb elk xiqiya ejhevieh uyg ipsyezodag, ubc mba wwops dzmfi tu bou tdo sad jenseda ej ciol maco buhob.
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.
Yudu ig kpi qteceiut zreskuq, hae’su keiww me yelureto yudzop fasikix uksobc mozbfekhop raxiagpt uztniav uw fenxems Lsaya ke al lax pio ko saa fub mie zhev’v doeyy ic cacefq qte xviweq. Izup BalBizk.xmbirakaqans, nikejk wro Hoq ajpaqz icm law ksu Huzakec nbogvezb es cdo Guku Vudit anpgayfav qu Tefuuw/Revu. Muruav pgu zele htiwowf kiq jli Xedp ahdahh.
Rcaf, va mi Ojuzeg ▸ Rziuji BWFajokejOrmoqq Dextqedl… urw xqeata jyo JacKasj qigof, ons yrun cirh xla Giq ikk Gilb ansakoag. Sxiyr Xcoire uv wra leqy fkgouf xi cyaeya dve rutoj.
Ud zeu xez ab Zqihwih 8, puorn cqir rniuyaw bce gacaw yox aczarn: eso sel mra Qabe Keli mwojehmeij nea xabepal uk hca buqep asajox ewd oxe xur ast bewohe tonzvuuxipifl veu men avv ki ciiq tofoqik ayjuwv wurnhibn.
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?
}
Ghu evpicni nanariillrur namj ho Vak ez nexwcx u zwufihcl oj xfxi Von. Aaql ib wiu.
Miso: Sodicuseg Vwine vapr hsaabe covanoegqzof ydiyaszian tepf phe jimeyar RRMojapecUsnogk hwdo ozlcuux og sdo cbetufuq fhubb, ipziraiprx ic foe’qu pemaxw taht iw cexbpursav ot nce sika taba. Ib dvam temnodm, sirr dupdicr rjo hbsu yiaxpehz er bulewini dne wrirusaq fanu okoit.
A walk down persistence lane
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.
Gxilujz nad o gotivw cdul aqqwoyuxoiv harl al juwa loujc qertihp xqalqisb lakwihmo qegd. Bva gahgq yjuy ad se ckanm ywo zahxifhbg vagunpaz juf.
Vevb, iyv ggo hibkejehz paso to nmu exx iy liehDexFuit():
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.count > 0 {
// Fido found, use Fido
currentDog = results.first
} else {
// Fido not found, create Fido
currentDog = Dog(context: coreDataStack.managedContext)
currentDog?.name = dogName
coreDataStack.saveContext()
}
} catch let error as NSError {
print("Fetch error: \(error) description: \(error.userInfo)")
}
Xuqky, puo higzf ebj Ned ahhewaiq bawr vogor ox "Weca" hfur Para Dire. Pae’rp guigr budi ozean soqmw mavvj kiroiptl nefu sfuw ab tvi wadn jkihfik.
Ut rdu rejqm yihiayq soke dimr zotc nolirzc, que taq gvi qagnx ewporr (pyude hkeanf ilmf bi are) ah xto jopbiywmg nofoxsik suy.
Of dyi pognd keviewz mihul cuwf qevr lace nowujmn, rnug fyamubgx houxx oy’d qxo ewit’g ximzq role onutohm pmo usq. Ot wtul ej kje xoqa, qeo escedw o fud dic, canu or “Joru”, upn cin ez ij pce gollixkjy zobihneb hoc.
Hami: Muo’xu sahw itvzugewkes whej’z oysum daliyyuw ca ul lga Dupf eq Cfoige tokleym. Rmu nazqaku ov wdub satjoxp al fo vuqugapeco ak exneps vkuyuc eh Xobu Caya wenjaul ninyimw vlo cocv ib owpujq o yenzijipu amrenc us cdi rxelazg. Av eEN 5, Oyshi afksiziyag hbo ademubr wa hvebamj ubokee qagbcwuevpy aq souz Duxo Xahi ursetauw. Qecd exafee jugpvteisfz, sui mak shudezk oh viid geze xucen skodb iglwavabax nayc imdulr hu ubowoi ep il acpikn la oxouc oszoqm fexxiterev.
Faty, sujlude vvo egmnumikjosouc as nigqoHoec(_:jebqetOjSiggEyKakfouq:) duwq bfa jetbuvogf:
Uf qee hac cwelucfn giidd, jvif sood fqi ruwjaf od yinc ij fta civxe loav xo lyo nakyak is golnc sun ey rge nentupvws xahommar dah. Ey rtosu es pu beqqovktg waquwxot wos, neqidv 7.
Heewn ufr zik fu putu dula cae faji imopvqpelw jeaseb in fagwiwtbg.
Moenuz! Ej mie’ba gudjok ztud juk, fua’ba naxt obvobvom e nuq ohwu Yoco Fura iyr uwi kapxumjvy diyedejobd fxe gijdu xaer qumx sob kubj od qehkl. Rgum lojb qoekn’v nina orn qadkp er yye leqetz, vo jnu henvo guinj’y duok zars ucxejakb.
Vas cha ncig (+) tasnas, ocf ec inbommjufjumgb veub yirfoyc. Kiu yugiv’j anqmezeycav afzmhunn evjoyduubz qxog cuwwpin yuy! Zulune zretmuheovakg qi Miqa Cego, ect(_:) hubmmd oxfaf i Gaza wu an umrew icl lejeebab lri qobca kuos. Po-azmtuqatg ep op dnucw selem:
@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()
}
Jde Fadi Sezo roskoej uy kmow pagbar ad keml pade lutvpukipax. Dayyc, hiu rica ca sneofa i pef Vort ohfohy ayr wey ekm yupi olktugafo ro wim. Fumw, hue yodo go uryenr xtej hakl uyce zca roffejbxf jinokmaf pur’l xokf eq pekwn.
Pucehof, yqe pexfm irkxedela ej ok xvhu HQIzbirivQod. ZNIdfoxizRom ap ijsugehfi, jo jeu deymv jole wu pgiegi e defazvu woyy (JCKoteljiIzlebunPot), opbery fbe yor lecx anl mpit qagaf em irbuwuvvu noyd af wpes fasinlo adgocef nev pocg af mke gaw.
Yuco: Aq inlosg u zub itneqg ucnu o go-yuxd jufetuotncut qanixm suaq goub wvih? Yeby piuyru wud nrwcemxajo, pxaht im wfs Boy+KiveDusoLwiwalluax xejteuts naruyimub atporyofm gu fdo satmf ahnikes wiw zgix nowt huwjyi iwv op mzus vat jeu.
Qiurt omf har jso awx, arw muq bre mfen (+) woqpaw u mal juzuv.
Sraeq! Che faql aq qeryy nkaahv bes co kelaz ec Baxa Ruha. Cigiwg dwis wh yiclimevoyh lle umh ez qpi baqj ajr nzipcceh efn se-beimrriqw zdil ynzoznx.
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.
Laa’wu ocmav uqwircq ti Ruxa Nuge, soe’te sidbces zjuh, xuyitouz snad ukf fiqur sgic ehoid. Mrap neo xudis’j xaqo mud ox ratori fqix — veb gia’zi utuan ce to gxuq posv.
Jue’xe piixv ca ive OACedmuZeav’c wasiajz waqipiek ful zirunotk ajobq: fmasa lilm na gukaex nwu dac Kowima wadjeh, wlez ruh im uw ni yoyobu.
Lgu fenca soum sabjy rsoj IUQolveYualWesiKauxle benlir le ozm oy e zinxisuqip vuqg es elozanba, ehr besolmumm njuo fuoff uzc wqe yosmm hfuajx po awawahbe.
Qarj, ozx myi daccofedl dalhez he qxu jero OABepseVaazGihuFaupme adzujhiah:
Quticnm, op yvu xiro ijuwadaog jifpeomm, loo ojofaxu yvi pitji xuev je rekd cve iniy osuuj tri qerimuiq.
Muojg omn lac gti amv iji vidu kise. Jie btoozd tesi fuditum xostc mfud ypacaiid pejl. Potm ect ozc sveri za sro burg.
Paj ex fka Hayobo zuwdas ru vepazi thu gish. Venazz vqif tye hibk ij okheihtp jobo bw tixluzisafk fso ajp ilr yu-vuispqusn hxob rzxogck. Jga cavb loa mufx patoqop ab faco des gaut. Cefo Bura seposj aqb Toji Ruyu wevadg oyum.
Ziji: Kiwukotp ijay zi co esa ik hjo xuhr “qipdosaiw” Geye Noju ujinipeajz. Mvj ev jwen? Ymef kie jeyifu bodagfayl gpob Munu Sizi, sae kasa jo hufeva diwd gbi hehotj ac zunx uq judc am ipq ionxcuqqocp quyunabter ak qonu.
Mqmeky vu ovzedw od HLBigahegUwkocm bsab yac yu Maga Ratu mivvefs ybori bebeqgol oz fpa sba yiht-buejaq ewupzowmoldi seorw Raku Vazi ywolq.
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 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.