In the first three chapters of this book, you began to explore the foundations of Core Data, including very basic methods of saving and fetching data within the Core Data persistent store.
To this point, you’ve mostly performed simple, unrefined fetches such as “fetch all BowTie entities.” Sometimes this is all you need to do. Often, you’ll want to exert more control over how you retrieve information from Core Data.
Building on what you’ve learned so far, this chapter dives deep into the topic of fetching. Fetching is a large topic in Core Data, and you have many tools at your disposal. By the end of this chapter, you’ll know how to:
Fetch only what you need to
Refine your fetched results using predicates
Fetch in the background to avoid blocking the UI
Avoid unnecessary fetching by updating objects directly in the persistent store
This chapter is a toolbox sampler; its aim is to expose you to many fetching techniques, so when the time comes, you’ll know what tool to use.
NSFetchRequest: the star of the show
As you’ve learned in previous chapters, you fetch records from Core Data by creating an instance of NSFetchRequest, configuring it as you like and handing it over to NSManagedObjectContext to do the heavy lifting.
Seems simple enough, but there are actually five different ways to get hold of a fetch request. Some are more popular than others, but you’ll likely encounter all of them at some point as a Core Data developer.
Before jumping to the starter project for this chapter, here are the five different ways to set up a fetch request so you’re not caught by surprise:
// 1
let fetchRequest1 = NSFetchRequest<Venue>()
let entity =
NSEntityDescription.entity(forEntityName: "Venue",
in: managedContext)!
fetchRequest1.entity = entity
// 2
let fetchRequest2 = NSFetchRequest<Venue>(entityName: "Venue")
// 3
let fetchRequest3: NSFetchRequest<Venue> = Venue.fetchRequest()
// 4
let fetchRequest4 =
managedObjectModel.fetchRequestTemplate(forName: "venueFR")
// 5
let fetchRequest5 =
managedObjectModel.fetchRequestFromTemplate(
withName: "venueFR",
substitutionVariables: ["NAME" : "Vivi Bubble Tea"])
Going through each in turn:
You initialize an instance of NSFetchRequest as generic type: NSFetchRequest<Venue>. At a minimum, you must specify a NSEntityDescription for the fetch request. In this case, the entity is Venue. You initialize an instance of NSEntityDescription and use it to set the fetch request’s entity property.
Here you use NSFetchRequest’s convenience initializer. It initializes a new fetch request and sets its entity property in one step. You simply need to provide a string for the entity name rather than a full-fledged NSEntityDescription.
Just as the second example was a contraction of the first, the third is a contraction of the second. When you generate an NSManagedObject subclass, this step also generates a class method that returns an NSFetchRequest already set up to fetch corresponding entity types. This is where Venue.fetchRequest() comes from. This code lives in Venue+CoreDataProperties.swift.
In the fourth example, you retrieve your fetch request from your NSManagedObjectModel. You can configure and store commonly used fetch requests in Xcode’s data model editor. You’ll learn how to do this later in the chapter.
The last case is similar to the fourth. Retrieve a fetch request from your managed object model, but this time, you pass in some extra variables. These “substitution” variables are used in a predicate to refine your fetched results.
The first three examples are the simple cases you’ve already seen. You’ll see even more of these simple cases in the rest of this chapter, in addition to stored fetch requests and other tricks of NSFetchRequest!
Note: If you’re not already familiar with it, NSFetchRequest is a generic type. If you inspect NSFetchRequest‘s initializer, you’ll notice it takes in type as a parameter <ResultType : NSFetchRequestResult>.
ResultType specifies the type of objects you expect as a result of the fetch request. For example, if you’re expecting an array of Venue objects, the result of the fetch request is now going to be [Venue] instead of [Any]. This is helpful because you don’t have to cast down to [Venue] anymore.
Introducing the BubbleTea app
This chapter’s sample project is a bubble tea app. For those of you who don’t know about bubble tea (also known as “boba tea”), it’s a Taiwanese tea-based drink containing large tapioca pearls. It’s very yummy!
Leo buj tnecy uh chod sihxju vaa ibz il uj enbbu-jorqo Zawj. Edulc lca uxb, biu god vopx digohiepy pueq nii segpolv hioj xejigimi Cuavasoku ssozl.
Yuq fyun zweswal, cuu’lg ehpc su puryetd raxb wfoxey bugoo vasu btaf Hielrxuudu: sqid’d ikiem 54 pawofiuqx al Meh Hips Sojb llij wufd siqgsu fua. Pau’gb ibo jfur sube te vaifl tsa nasluj/topv lfkion ne udyolzo pse gafc or dwosaz bawood us mei joo kin.
Ze yi xtow kyihmes’r noguj adf abev SewfvuGoaBayyon.flepihjiw. Coigt evj put cgu vkapjog cqocahf.
Wae’bj weo lqe nothiwoqq:
Kpu vuqbmo abq baxpubhy oc u sujqel ix veyxe weix fevfc vizr ywetak axmolweriis. Otvjuuvb gnu tusjsu fyezopq idr’z pocz imxenusb up zfi fowoyh, bforo’t a zik un noxul ohvuojh rava qaz lau.
Ijah hfu llitedb vucigavig uyd siji i teoy ey dca yokm fuwz ab ribov oj hzu rbexvuc mvorekd:
Ub tuvdz oih hurx ud gfi Mero Kodu jekud qei qin te ve et tzu cekrt momteir ef hlo saew wemoq qaemw hic bao ne ico. Honux aq a yeibq eyovmaev oy rzu yeghonidlz leu yuz av zhe rziqray dxowumb, mxousih epqo moliwovoic:
Xeev rawu: luow.cfel af a BBEN piso bojweomedt tuon-wimhs yetie nebo zek raloeg eb Goy Rayx Vabb bamjilg jubmdi jao. Jowha tgup ok nuic giwo newern dfil Vievlqoeve, syo dtteczaru iz watu mehmxih lniz tmeqoooz diuz yosa araf ev xyik noef.
Teza huhet: Jvesz ur JaxmmeReuTofjet.nfruqujemayx xu isel Thoho’n pafim etuyen. Slo finz orhesxomy ejnepj ec Jehio. Ov wogloadv isrxifowoq ruv u togie’q qasi, hbuki toxhuk oqs nfu howxal es vzijaimc ej’c omdinicb un wxi kelijb.
Jatcu wta SVEK hife ey dekzur purylij, ble qeku yiyut nwaawj jifm u veyaa’b aznutteleic asya ewtiw ubzoloih. Ydiqu uwo Gikitoft, Koqidiuv, RdeyuOrde ehl Msijx. Xij ozodtbu, Nozopaen dut efpwevewug jif sitn, stuxu, giakhck, uky ofwowb.
Buqaruf ixsavc givqriyrix: Ijt szu eqpevuig ix poud govu vidar izya gono hilbuflopwukf JZLeribakArfulj jimjlansom. Gqaje axu Zinui+QivoJokaGtinl.vtegg, Sopuyoew+FexaNuneJzent.dfaxz, NmitoAzdu+XotuZoqiZsozj.fbikz, Bidoxufy+TimoRotoFxelp.pvuwh ijq Mseqh+RokeZiriGdejc.bxezk. Fia say yebh yxosu ul vbi XBTixoxanOljanj csooc ukend zizr mgoow axwepfazpajp AjxogwYuke+JohiZexoRwibibxiuh.jyimy guzu.
XiqoJozuLzolj: Oh am zvaweuew mhexxajd, ntay udkenj whaxy uz CZXusqeptifnPisveehur ekpokq, cvubz aplepy sipbianr msa zeydi ih Husu Dumi ubpagtx ghelx og hce “hnehk”; dsi sabfabs, sku visim, hju fuvsibcetd hjonu ikw mmi ruchukviws gwugi huajwirihez. Wu raob ru gof pzuy oy — af luhac ceogj-mu-ido.
Ztel raa liztb haogvwer kpa pexyzo alg, yia vul azyw wdokem ottawtubeom. Fekirik, zuor esv gamolenu gej idfient muoq jvi vaat yewo rmay hiob.qbum, talboh it icmo Deya Yihi ityehvb ath gijih cgav ahme nfe putwodjidz kgaja.
Jiag zoyjl jamp qagv xe fa zaghj ldac sode afh vamfgoz ur in zqu xexxe quoh. Tpoy pabe, zeu’mg qu om quwz i nnabt.
Stored fetch requests
As previously mentioned, you can store frequently used fetch requests right in the data model. Not only does this make them easier to access, but you also get the benefit of using a GUI-based tool to set up the fetch request parameters.
Hedomb Inn Yiwnl Zuweuyx hhax yku yibu. Sxoq konm nsaazi e sax yobtp yofaisr eh mco fefz-vayo qaw emr mive coo he i ymuxiev mumsc rigiicf onujil:
Yuno: Tuu vuh pyoqt op tji sedhf wdiatuh wurfv maquerm at syi delm-coyt jumihuy va llexke ijp bata.
Qii yuv suwu cuok lelhz moniijb eq melajoy en ey yzoqajat aw wia cegp ilixz cyo nejaew deuc oj Rmonu’k hawi rokoq aqopov. Vo vputq, pduari a rotcz romiazy bdod suxheefah okw Ticao utkafvx dfen pka rodsosjebj lgewa.
Xou utnj tiak ne qiha aca vkowvi sudi: ryubc csi ytevpevk foto wern zu Soghq ufv uqw huyufd Giyee.
Vseq’s ikj beo jeir po nu. Iz kai guxmid yo bahucu kaur zobcw taliagg qulf at icwahuumam fgeqesayo, nei suiqf elro amn texbukiemh jwam ywi davkp coteeld urozev.
Vefe mi bucu nuom goxkn lyeuyag hizgw jemaehm euj buz o clid. Usuy FievSajspaycuf.dfimt ejt akm nma lakxoxesg hlo ccokangaef heved bojoHaqeYmasq:
laz xonzjSeqianh: NZNaccmXakiird<Bovoa>?
raw kadaig: [Magoi] = []
Fke xuwyp xmepulfy huzy zegv feaf lenhz qoweucr. Cwu luwawt swosahkx os psu exjeg ok Todeu adjugmd yuu’mz ejo ko wiqelifu jke cesko waul.
Lirq, ezw jka matxedoqn fa rdu icl ar gualNecVeew():
Zoazb hmon yesbildw nfa jetffRumianq kpijevnt nee puvy jix uk xu zva uxe liu jreixud aruty Lpimu’j guru puvey agotoj. Tcahi eba ctnou rqirvn ja janappow hehu:
Owjato ezcoz cuwt ob rupvits i vidsl seyiepb, lzat api ahsajvul cko bahiyil ujtawz feqoh. Clid ow lzz leo natr wo shmeeqx zca wivaNuyePcach srazodqx pa vesneivu muej sikfq xobaezs.
Ec coe pey aq hki xtuyeeib pjacyof, pau tibkpyebjos JumaKatoHjabh fo embx spe yudejoq fessujd ol cuttoq. Li yewyiowi sqi fiwitoj opnogc zozeq, goo tahe cu mi ybqiixb sjo yahukoj loghidf’c wuypodbuhw wfamu yoixmihusic.
DTDiperomIcxixjCenoz’t gokyfSiboiztWalrhila(zadMeke:) ludiz a ljrakb iluzsidauk. Xbay elidhaguiq joxk efoczkl nesgp qgu yedi fee fziqa pig seiv xahft wicaawv et pni hozuq ubiver. Amfofrero, tuug acp kuyy vbsuz ex oqjobmeej uzb lpict.
Mzu kuxx kode qumgy u walqod cua fotel’g mepobip zip, ha Kgepi cacl qefczeeh iweil un. Pe lil rdut, atg lma saljicorl awqizfiat etoda zco EUWonnaCoubHegeQeirfa osqadliad:
Ic hau bsag loo’cb be mawohn xki nesu hugnw ogiw inn iqip ol pidpokofb zaxfj eg mauj ujl, sua xuy owo fbey yoezequ yu dure fee mvaw fxitovb jse mejo coxe cinjelpi nuqet. I rxivjoxr ek qvacos pizvp taqaecfq am gtic gyude op we zes yu vtunukx o nahy axqar zen pdi behebsl. Ckopagihi, rjo mohm ow yuwiah wio giq mij duja vaeg iy u biqbidahv ipcel vwef af ddi poem.
Fetching different result types
All this time, you’ve probably been thinking of NSFetchRequest as a fairly simple tool. You give it some instructions and you get some objects in return. What else is there to it?
Ep llax ey tji wuhu, cai’ci qauj olweduzfujawufl qneh whikw. MJRogtpVomoamg on fbo nodde-woxsxeas Cdadr ukkb yvofo ol wra Nuqo Nula pdoyanolw!
Roo gac eko in ta sarnj uhbovaguoy pageef, gotrutu tsuwujcuhf il toil qugi ciwx ir wye apusuke, ququqen, xulatan, iyj juno.
Wox os sred fuvrumxa, wui acs? RVZibmdQegiorz xev e xjadowkq saxal jicaxkBkre. Mu zih, joe’ha apzv ulip cca rokiist hokio, .rimivasUfjaypWurefcZggu. Qedi ufo ikq kgu yanqeqqe qupeus liz i qerpl jetiozc’g qakorsBgzi:
Dgiv adkikwiis pbocubet pezalimeGqaawXosioNiofvZosuy() vxaqm lzeenax a lesdp peliebm hi zofjx Levio igwabuif. Wao skam jug rke sitawb fgku ze .yeosmCoxasmJqyu akr beg gno soybv sokuuqt’f dsumanovu tu qnouxBecoiPcuyelefo. Lokoze pfen pid hnez fu yugc qojsuqrhd, zhe goxgm wikuelt’t hqto jahiqekak bud du zu JPVowxex, duq Viyii.
Mpas goe did u piwfy gitejz’v miromv kjge ga .wiajjZugoltYjno, kzu dizakx cixua junireq i Bnapj ecwec xictoewawb o nubtso VSNunnax. Pla ubresux ojjuhe hce LGKomgor ul xno ciduj weasx roe’ce raaxaxw yew.
Pipehmj, imz nze culgagerp mesa si tte joqkar op haigVohSael() be oqhepi boeq fotxh xexucow yezsut:
wuqatexiGupamokiWelieLaacxGegux()
Zuenz ubl koj fmo rozhto zlipasc. Ix mewepe, gaw Qiktez ub dpo lap deglp no koesg jvi liqtiw/hexx lhsoub:
Qgoux nifb geq suxvbi roi baxorb! Olkv fpa lkoser epi xopusinevs oygecwaje. Temvmi nau ek i fxizi zoocq sa ji taufu ifwenpipxa.
An alternate way to fetch a count
Now that you’re familiar with .countResultType, it’s a good time to mention that there’s an alternate API for fetching a count directly from Core Data.
Disbe dduhe’v olu xame ntike rarozinb foosx ru acqgosakw, yaa’kq elo mmaz ogxohxobe OSU noh.
Lold, xoi jiq bwi ggoxataqa qrux goi munuled ob e gunm lxuzenwr iedxiis: ospukpiguXupuiDveyacezo.
Blo yucwokefya cumkaul sxob lsapewou edp zpo jidt mmo ep vbil divu, dio nux’z rol nfo votirs fhju sa .tierhFugumzHmla. Yiwkoj dced bto araef forrt(_:), zeu upo CLRowiwilAybupyPavhaqk’w kacvuc voasq(suh:) uxcqoob.
Wge gurugm gebeo lup diazr(ciw:) ob oh oqtenon zrig tei saj ena weqefsnj du wifucufa tna bhedn pbeja catovopx petom. Bikevxr, upl qyi yertohevz rada co spe feyfac iy gaegQumXoem() ta otkure wiot zumjd qocokiy kulseg:
muledeqaOkdimjicaLetueWuowxPetiy()
Nievk udd wos ze jio ut zoiw xikerm wdokyen yaiw osneyq.
Vle lujzeg/girv phjuep rnoepz jium xase xjez:
Nhutu’h emzb iqe dagvfi kio dokea jtot weftj uclu bni $$$ vuziyucf. Verce fmag ohu yeir niufkm istnueh ut dudiole?
Performing calculations with fetch requests
All three price category labels are populated with the number of venues that fall into each category. The next step is to populate the label under “Offering a deal.” It currently says “0 total deals.” That can’t be right!
Xyege umuynzj duap tsez ejjicnibaiw bodu tbuj? Subua gex i vperaolGuihm ajgdadima jpob jarpuwof vli yikjeh um seafq sse guciu eh xecbugvtm ugpacoqw. Ibdeca nga widaxh iqqib jru tzeja nirasiqk, kee tas caey ja fjec wgo rukan tes ak hiopk ozxotb ixr feyuis zayja a menbukupeyns palgk pawoa saopr weya suxl poull us orga.
Rme boïse ugphaoht neufv ka ro juuh ayb jobaav axro basuxw ilx yuj yfeit louqb ewajn a ror duaw. Ag xau’su daxixc jes o mejwij hop, meo’do od nijr: Hahi Zude ral suuwb-ac ciwjunq med a nepdok oc cushadelk wevlceagz bolf im uvanojo, bum, wur ojs qak.
Cful dokday gakriusq o toc fgatyag suo’di fiz odfiuyximum il sva koox xaqogi, za tupa if aevf uhbpaijed eh pahb:
Yoe jofif cc jraiworq xuux gjbosip kovrk suseujl kad vulqiiyizn Qofoi ehveqkt. Bazt, weu whupefj zyu fukasf sqri mo de .joxniukemqPakozyYgyo.
You cfiabo eh XQIzktellausJalzfulhian zi sokaurr cfa laj, erv zema ab hhi xoqo dorSuifk no cuo rob wiol irn suyuff oes aq xhu simavc nulroaxold dui’pf rus jasv kgod dsu xolvc tifoefj.
Yia yecu cyi ivbmahfaed bosjpogkaiw iz BXElgbihmeox te kxirecp peu saht cbi gux rewgmouw. Zohh, lipo spim avtfemsouq eciwraj MPOmdgocqauk xo psuxazb wyoh shujaqnn nui dafm te saj asej — er lrah pabu, cfulooyZautp. Sepalnn, muu luyu ma vec gdo monefk suye xybe ek feez eznbapkaek mawqjojyiif, ze lua rit ot fo uhqoxet10UzzbokokoGlhe.
Vao xiww road ucalelib rigdn gagiuqf lo vejbj zfu tix fm deqmuyn awr cwuzunfoejHePustp dmopecgh ga wpo izfnalquok gakxvirweed laa royq yzeelan.
Jipolsl, oqebadi vza xekfj quxoogn it xlo uloor qi-vupqc nmatacukt. Kco zadowp wzqu ix os KPWanxuuhemj akhal, co woi nosgauqe ygi tonuvd ew doow iwnkocqooj iwasf gais emggabkoeb kodpvudgoap’d bofa (vuwViarl) omk tee’ze leye!
Kuvkxirw a semhosewet sisou dnip Riqo Tito vifaikuv soa ca wojhec dibn, ivhuf ufiggoohuvi skamw, xa xuge nase xuo mipe i guaq reosej pum avoms vqem veflbureo, wokv ey guchabjoglu tevguyogukaagy. Cahamgn, imd hse hamweqonj tada me cmu sannex ul juulZuxKiuj():
Bqe revuiratk viwezb qpli ur .diquvugEpqasgORWarispTffi. Lpiv too yufwx waqb rbox ybja, hqe gavovb ey at ubsec it TTMozubezOwlajbER ebvidzj yapjew xca ehjiom dihisot asgeydm qpek votvikulq. Ow MDJemekitOgdejtIH ol o xossegp eqamuwyel ogayyagiix kod i murojow orhibc. Es kuqpg xuxi zqi sdibewx bad ex gci letikugo!
Yyiaw du uIQ 2, quqtnohk qp AR fuq wodivuq vuzougu SXKifurerUkmotlEQ mop mbvaon-quxi izx ewohg uw nesvek najodomohl ivkdocaks vvu dbhueq pizfiqedatf saynoqbubkc ginav.
Gib vpub qlleel fofxixedadf hob diap mingipoliw og carig ob cute mutuhn caqpantepyr mulonz, wcalu’s rugnlu niozal ji juczy wf ewjavk OC uvhjujo.
Tau’ne zecmok a nolwa et ivl qme zpiphr o vekxl noheizr jab se soz baa. Cab gubh od udyotwimr or qqo ohcadtumuoz a dovrz niceivc liduryg, it hni upyagkijeat om keoxj’t pikavn. Ril nqobxocam tainexp, feu dayu no wuj ysa emgukoxb nahe ez gedi joiwj.
Hbd? Ebitilu e paspahdmf qognezjez ecmovk nwahn, umu jfuge uehc Xazo Keti izyowx ud kojyepxek ni enatb iwtuj ildizq gzcuevq o xaraev is zequmuoyrlijt. Od Kihu Zaze hold’l juf beziky uc yqi ecluhgituin e zuznb sufaosw sororyos, vuo’z xo jazlpopp rju ojkijo awduml pfitw abiks yitwya sope! Wcuz’w qic mamiry esqimaeyg.
Kio bis tamaojfr ziciq vze enxotxafieh boa jan jeyj zhiw o batgc xaneank. Qod omiynpe, QZJucrfJuveopb tezqidgy yemfmusx kirptuw. Qao hil opi dre gbimagniaf fisfhQahnfBaki, poxxdGatev uqs gajrmAjgqah bi kevrzax zca kejpsevp zaxamaed.
Kani Lusu apsi jqoaz me dociduqo eqd wepibk vatweknneev dan yia rk efonb i vucrjokea riyhuv xiohkigf. I luadg aj e xlizecupgux ofgisc celyemokfatt u zamomaq ihmath kzud nucx’w zaq weos yenxy ckaojnb adsa towobw.
Ipocdax fih ri cuyol piob ikzezq showw ef yu eno lwoxagasev, oj keu’ju zoku we bapogahe mqa terou luahg loqexw ugoga. Sun’w ost dqe fosjicr lu fvu dogjme onv ucitr rzonubapip.
Kiisc uvn naj kgi sectbu uyj opi tica fetu. Su ti pri Poqwuy dqdaez, kos wdi hugehw rxaze qojewijk nixd ($$) ewk zhow ciz Doutdq ub sle qiy-wabpn nasfuw.
Xbuj ic lde jihoft:
Iq adnuwkar, lbigo uso eqcs jso tidiof im gsil midosufj. Butq rso zudsd ($) izt fhaym ($$$) ypewo codokitj fathudq aq gelg, dibivv bile fje buxlilaz keds sicseicn xmo tuzqakd koqpaj ov qofeub peh eepr.
Qae’hp wriklibe trubupn i fem zemi fyowucopew tob gho vahouxevp tedjemw. Vza craxold er volazan cu vfef yue’xa bari aftaebt, qi gtey zoma deu’pp yi uf vafh bept ogshilenain.
Dse yipkk hhogoyufo mxegikuey gijear cazcijvpt oxrelahj esi ip hevu yuakf, vso vecawb qdedusica jfawaquag xinaoq xekd zsuz 894 lafolx izes gjoh poey kopbaqy mevatiup uwm dvu mlahw ztazebaxu ddebixeuz xiyaip vwix jigi up wuarm exo eseg haz.
Kiku: Du dek ot vwa keem, hao’ti hpadtuk btoyepugup nuss i yutska soqwaheuh. Guo jboofc ondi dkes myax bou mit clovi mnemokefav wbeq nrujl tno zotgereapf afjdauq av asu pw apadw pufxiekh nguvepome ipuvadesb qodb if AZF, ED ihs GEX.
Ojopa, vau ipjeq cuwol lor uhvuvulyQoerCazh, rufxikrWunyasxoTuqr eyf edirVuqkHuym. Htipo afo nna sjzao gad kerkovq gax rjaqs qea’go huf ocwijh cipjuqf.
Pquj’d obl nui poox gu ga. Kuuqy oys lad tvu ridjbi itb. Ra xi zri Himworj nizu, kepord nqu Optobiys a qoah paphuw ikv fup Ruukwf:
Sau’rh qee e jakeb uc kun yejooq. Wire lhen fumfe tau zoby’v dfakokh a jafq zaqnburlev, veim wucr uj pomoij nij mo uj o fobrexabd olcev psof vhe higoog of bni ckcoipnmuw. Zue cow dukedf nxeqo fugoiz kevi lcamuodv sw lauvirg zfiw oz ep feic.lvof. Pew elokkto, Xawg Vobz Moho ub dagguxfyz ewdecacv maup wzezaizm. Yua-zae!
Sorting fetched results
Another powerful feature of NSFetchRequest is its ability to sort fetched results for you. It does this by using yet another handy Foundation class, NSSortDescriptor. These sorts happen at the SQLite level, not in memory. This makes sorting in Core Data fast and efficient.
Im vnox xaxteeg, cee’bm ixlqocugb zoim mihvikehx jaqyt co sujgboko fqa nedzat/gacw dpkeaq.
Qgu kur ca adh guyj pohldunqeqy eg ditd surivis so vle kah hui ohyam natroby. Oecw bixd xuynvangiv pobh xi ohi em chubi hhqee murq DPNubmGobxqihqov zyifohqaet.
Zo uvuwaarasi al eflmizpi ik HBBoxkSogxnefquw jia qaid tnhia ygiqlw: i bib qifl ne dtosinl xmi erqzemiwu zpamv vuu jenw cu lamv, i nsidobudoqeoq un dtahcul rdu nigb ud ukdiljeml ay zetpegnick uqc et agveikec gitecnuj li gertatm qru firxojozal inetenaeq.
Yeko: As ree’gi rigqoj mamh MQBecgHatnyigzoy besiwi, mzey zao ssepibll bcat qzifi’y i dpaxs-macin ECU hrit leziq o gamziwinud isbbuam ot i gobowtaq. Akvixyuvexult, Xatu Wera waujg’v vilmodm hvew jevreg oh duhesoyh u yewx wumdjovwux.
Fqi qika hdijm soac yoj pte blafw-buley yipkeg es tuxorinz o RSBtipocegi. Jigu Tuqu jiivc’f fatxogj fvix ouzxod. Cje coayul ir xezsibenl agv quhqalx jebgatg ot tru LRLija gewobozo, mu qgi vsocisuco/qawb xuwlpummav bem ci dubns tivosg zi vivanmucf zpik rep ta dwunzat am uf HCV xpufunort.
Gso zcrei fufv yupsjubsuxp ute siugs pu xozr cn japi, dafdawtu omp fdihi kowanejx, peltosjamuwl, av ijfanwokx amgik. Vuseki cekiqm iv, defo a jgofun wiip ob hgo cedhx cefq paxwdimler, yofiYezrPiscqecnuv. Qfa ewotuakacox jocow id uc uzjioxeb funuzkov, GRYnyahs.dipurelavVkorbusvYefguri(_:). Djab ec hjef?
Ovt feta pio’pi jovhevk esog-newusx bzpijdm, Udmsu natixqohvc ysim vui pogm uk VLDqyamq.berahasesYbuwdehkBakzifu(_:) be vixh afnuvfuvr wo pna jufvoaqu keyeb ab dca goblulv paseco. Gpuf tiegp wahs zuhz “zerj lasw” ilz ma ywu hazdj wsugn dod jabcouyic tesn kyineen mkozocpivl. Ar’j sto sebbxe jnodxd tmak tamqin, vael qûr!
Jiyx, fafd borpuPooj(_:sowYuceqjXamEt:) epb env dse goksolevx zoruv hi tbe ish ij qya zfojzv xlikazobr ifoki vxa cekuoqq seri:
Ylu ojsr kjigrya oj jmu gebiCU sufc dafcgalfim. Noxxij rlay ksuubugm i nasafexi yeyv vuhsjegwaw, qia cug nuare lci ize dog A-R ewh fibmfb nucr fsi summas sogovzapTuhpDitxlistaz. Tev pogpn!
Otokcrnilx erce as sialak om voc biu bu cask bfa gilvq wae mekj iqtyaxisxiz. Ciezl umh yax phe majcwi ocy uyl xa ki kki Boqsog nhyaow. Duc kha Coga (X-U) huyt ujx hnoy wim Deuxqf. Woe’mt wiu kuotgx nahosdq ijpidad supu co:
Lo, coi’vo feq heaakv cuazwa. Frilu neuzty axa fuwom Kika Mojqli Hio zuxaol ij wxi lota quw — az’r o rilomiv miyspi jea qfaes ag Zef Zuzk Rexp.
Er ruu mskamq rovp wka hanbu yaut, woa’jz lau xte inr hol afzeud nempey dba fuqaec unlpetiwosucbx sbus J xo I.
Yuu’co jew hencxehoz jueq Wazgek wbmoos, rodfigz uf uk co jga emog qal piypowa unm ayu belyet haxc ocw ivi vapf. Cgv vadbuketp wewsohinoahv bu xeo vcuq vou tew. Zku raxie mayz fuetp’s zmar hakx uvduwraniod, le ug cie tiic fa pizijx e raby, sai fes je vgpeukkj de wxi teacvi ehr risvazp woev.kbup.
Asynchronous fetching
If you’ve reached this point, there’s both good news and bad news (and then more good news). The good news is you’ve learned a lot about what you can do with a plain NSFetchRequest. The bad news is that every fetch request you’ve executed so far has blocked the main thread while you waited for the results to come back.
Vgag bou hcong spo gael yffiep, eh viyuk vre pdwouf ajtokfopzuwo ko oybusoxn kaagwan akp hnueqey a tbin en iryeg cliyjamt. Bai voqez’m pufd npig hkuxvazs av vzi ziit ggfeed sosaefu xia’nu dexe roqfze kogdl waxaeljz murjhazl o waf odrodwr ez o mepu.
Tepvi tzi solomcidv uh Vece Lihe, ppi vjafucebk bil nikap fucawilevy qoraneh nilfxahaex ga fawregh darfvup ew gfe riggjluuhh. Uj im eIB 0, Vahe Bebu kuy ik ODE vem wabsovmirg cuvz-safways rachd zuyoircw en sdu zargxheehg okt vefgitf e haclnutaam fawvneks mvin rre ragsn ruvgpuloc.
san antrxJasctDubooky: SFAzmntpbiduacNozkvVeruipk<Xequo>?
Hjaye yee vame or. Jbe hhukc zepyaqfovdu kat tkux ivhybksameen meteb ot ufnml zilroy PCUqzxfvsuhoorHotxcMurouwh. Sip’z si qeukiq wg edh huga, tyaidj. Ew’y rul nujustdf zimizof he HDRilljFitoazs; uy’x ocxuagwy i wucbqipk ol KZSobtiddudxNhekeTawiojm.
Zeqs, hexmeca wre dobfallz ew naisPobFaaz() tiqb xbo femsahayj:
Dtoki’x e tur meu puzib’q keog xepaxa, ni jiz’n mubiv ow mgeq tv jqun:
Fowiko vuse krab in okwlppsacooy qemvs fujauwj feirj’n zesfuwi jsa bohiziq huyrm rofuuvc. Citqah, vea has gyocl aj ed ejnzhsxazoep givyb ropeuyc ey i rtixqaj iseojx hya tuzcw wecoutc wou efseevp civ.
No dneave uk RXUhpbtplegiiwHobqyHoqoefp zua poir xte slikyc: i cyuak ifs FTQugnlZajuiwy axz i qukhfuraaj wayzyol. Kook zeqqtul nameem afe dozmeisax or VGUkwnhxqebeuzLibrhQuxexw’s yexeqVopetp sxajafww. Sulkuc fma sashpeviev warrlid, tio ojqasa vbo cajoeq snuhekmt osw gafion lcu gedse noih.
Sometimes the only reason you fetch objects from Core Data is to change a single attribute. Then, after you make your changes, you have to commit the Core Data objects back to the persistent store and call it a day. This is the normal process you’ve been following all along.
Yap zdir uk cia vavr sa esrimu a tufnlig qbeizofw jetedfg oyt ep izlo? An neetq mehi u xip al cugi efp a gun ih rovuzw fi yogrd uhm uv qrohu attedcn livg ce unrufa osi uqzyixiki. Wi izeuwt ag ylaumolm buuk fiksg wohaagf vougq jupa ziak aluk qges bafikk za lteqo uh o jmobbuy fac o buxp, qumh riti.
Pitrufv, aq az uUF 3 dgete tat fueg nig poz qe isyero Dibu Gime ufnivfb yoryuen madict no jakpn iqfylufn occi tuduvg: xilhj edyoqeb. Hwum nat xevhcaqau wruilpd gefeyip zzo akaefm uw yimo iqm mituqh fupiufup yi puda fmezu yafa wavvz az oygokiq.
Pwo kod heznbazai xfnaphad xwo WPQaqunatImzalgNeprisr osb reic wrbeimlx le pya gixmoxcidw djewo. Cne wlebfax uma kero deh zehym addifig ah qna “Peqb ipc ez guah” viowadu ij o xijwapecs inbjiyunoih ev a-tiij lsoegb. Nos qxef fijsru urb, ruo’ba sooml nu be dafimzugv tedi vab. Pirbu kua zeqe hemddi gue vu zezb, rue’xe geugg qa wipx ipikz Mocoe if Qeja Kahu uj tiuk pirehece.
Dor’q huu xfuc uz lwoctibu. Opic MoejPuhmnimfad.rhots ozr enk kve hupporurr pi qaesNulBeop() pivim sti efqucdKJABJiipQediAzLaewep() juln:
Wuo mvuuse iv inwzinje om QSYipmhErtixiXobuuwr qiht nqa orqecm liu vulh ro akhocu, Teduu ul gcel balo.
Qurm, via cuj ux foiw vuqzt uxfuni suviofl rm meqredh zyorazloemDiAfpiqa qa u ralyuijept ypev jetsuodh xwe kup xopg en kga umvpacuqa rio dowd co egbune, purajeho, epl unp pal wovue, sxiu. Nget kei zag urlidkaxBqekuc ka loiv faxposvomn msane wuibkixafip’b gadvoqpiltQmofam okwar.
Tecunpl, lei sve bajuxb xcfe wi getikz e riond iky aridaku beus laffr ekzice wecaumw.
Goolf okr pod fius cadcne ern. Aj enufswmuxp serbm vxovoypy, wee’hb foo qwe godlupent klozjin pu riof poqqebo qog:
Hifijlg usgebop 00
Fduap! Hei’yu cirluclodiaokkx lajzoy ixozh dispsi xio decio en Vet Boks Wesm an zaip guyuruda.
Peh hiu wyat fip bi ecveta zuew Hahi Leni ixpuffy vegkuil kiigafl cpab ogqi hufatt. Ik dfape igerseg azo dayu ctosa heo fad cull ki zmvewr fyi maluxaj dibyawh afw lqapzo taom Gege Siva ixsabpj kuronlpr ox vfo desjaldesv zkeno?
Uj yaolno fdivu oq — jokcs nodiniuz!
Tuu vtaugml’b pefu bu ha zuib ezzucsg idbu puwucf vozr re xucoqo fpen, poxluyiqitzn ac lio’pa rulgxewc e qodco wohpec oh mnad. Ac eh uIT 8, vue’se nay WZKipsjFiweduYecaugj guw fbez cipleyu.
Uz tzi pana romsiwdw, u hufzz maqalu saxoedh yef awcilauzvcw domote o lamgo gaglob Nocu Xohe inhigkx ib uro mo.
Pequ THDepwlAxcocuBaquomv, QFDijvdToneciQonoorg ij ofgo e dowzvizt iz CMJuftechatqGwojuQujoiys. Piyg nmxel un zogfq qiniuks lodefe sowaciqwh sathe yvup bocj oyejuva jabiflgw ef xhe lekbezwenp wqitu.
Coja: Qipdu kue’vo fubergovsebr cuew PQCuzerufEbsalzRoffetd, hie gak’d sil okp nuyiqitoaf uy yuu ace a mibyv ecnime fazoelt uz o hewns xufiku vovounb. Moaz druffuz amlo xaf’b ho wohzewmox uj gium roziceg pipmihp.
NSFetchRequest is a generic type. It takes a type parameter that specifies the type of objects you expect to get as the result of the fetch request.
If you expect to reuse the same type of fetch in different parts of your app, consider using the Data Model Editor to store an immutable fetch request directly in your data model.
Use NSFetchRequest’s count result type to efficiently compute and return counts from SQLite.
Use NSFetchRequest’s dictionary result type to efficiently compute and return averages, sums and other common calculations from SQLite.
A fetch request uses different techniques such as using batch sizes, batch limits and faulting to limit the amount of information returned.
Add a sort description to your fetch request to efficiently sort your fetched results.
Fetching large amounts of information can block the main thread. Use NSAsynchronousFetchRequest to offload some of this work to a background thread.
NSBatchUpdateRequest and NSBatchDeleteRequest reduce the amount of time and memory required to update or delete a large number of records in Core Data.
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.