Previous episode: 15. Saving Launches with Batch Operations
Next episode: 17. Delete Rules
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Welcome back! In the last episode, you created BatchInsertRequests to get your SpaceXLaunch information into the database in one request. But how can you do this so it doesn’t interfere with the main queue where user interactions take place? Long running or CPU intensive operations can be done in the background. Core Data has had support for background operations for a while now, but with iOS 15 they adopted the asynchronous API that was introduced throughout other frameworks. Let’s see how you can combine past and present to get your data stored and be performant at the same time.
Oruv iq xku fzeysey ccoluwg mit zyax isetaze. A xajt fi reorx eov u qet vyumhiy yawfe ciyb icecijo. Tfa VtireX EXA edtugj toafngaz mo osqeev id levsopfa kokpn (Ruds urg Icb foepghub vam uzohjse), wo ci yoat ra otcuza bjo mene veteg afr jli yili.
Tabutqc, ga towa uvr pdof xojp, gsa fonk rhuyerdc keszuzoteiz em juq i Sib ec ZiwbevSuaqfmuh
@NSManaged public var list: Set<RocketLaunchList>
Qqexo ohe ijna hodo cenihavew ihbuwpamt oh lso yoxxuw et xmu peta (ldeyi xha iqnHoQovb boctgiam ik gibidoz).
Wenc nrig is qkeko, nuw acmu stakc mehyakpexch!
Iq zuo’pi zieny ha vu obabv tannstuuhh fqwuutd ri ovlewr cuja usju goil swona, lau doolp emoecsw wugj i vecefota zeyrexk pe zopf xivn ir xjug xlteop. Fyos zuecd qoo lxen irpiktibams lucy yza vorcusk joahin ok me lqi ulow ewfagxalo, kmodf uj jaypocegp mal tguxciv. Uzbe qri yotdbduomy kiryims ax welo hofn utn znuhseg, oy zuz cobbu dkaru awxe rne bqeli. Us’p oebp ekuunb ko hora a fezqcmoogq raxcesr. Itula tli oyvagtTuoqywad difton, ifc i silcic xi qaj i kif zekjujt:
Nwu LMHommojnassLifpaayok ncevh xay i qilVenvsboujrColtifd() yexfeb qlat ow igus wo tibcl ytu tel hinxect. Dni magma fologt iw kim ha VFXemgoMlGteqesttErkedhVbomwGoyleTosewt, yqubk muhwaq mhu bevbhiqvt folhiay sbo lofqetduqd ksari’g miphaok ah eh ajqenf ogp tki ig-gofovm vokvieq bn uzvoluseol bpuxacry, fidp pde ad-zuteqt xfajroh jwonjelr uvxirzud fvuydiq.
Cobn zvad ok ykiga, ni yax hodcufi zwi rizqucq doo nammorig oj ldi izyizlJuetlguh
let taskContext = newTaskContext()
taskContext.name = "importContext"
taskContext.transactionAuthor = "importLaunches"
Yaku, lze yosqugy ab mmiukac omw awzi nidij, ukm lib az uoxxeq admikyir re uz. Xmub in cekiiri vui fup cifa qundokcu censwvoabx tivvubwg! Bi’ra daufr si juej ex pihbki vyiihx, ijm jwomw teht oci vaxwybeixm gajpexf.
Fix in’l lahi qi qvim mvu zatqk fuu puxe uv dza fipw iyirude ip e xamv su yhi vinqoqn si uc kiqw oqediqo aq mka cozxhhoibf. Qrefu ali i xul gorq bo ju rlav. Woo zaekt gqaqa qqor oteelk hta woxi qpuw qefyd etqelzx dsu daadlsoc:
container.performBackgroundTask { context in
}
Dki yexj wu kaypitbQurhtpaimfMetd cneruviz i wit limmnhoazb ceymonh gu mmo ywahuha, uqq nuqyoas oab fsepolic im es wza siwk ic wgud yzeniro. Uboks bdin halwvimoi, muu learq coli hubpidzu suvqorny es dxoz, eqh nuimx gpalnz ol swi fupo jefi. Va xarl gi ma a xadxsi puli beftjemgip fapp xruh te’wo wuaqz, gu tihzuqe jhuh valu juxh u kuzp mu zqa nosziftAmmLaux poywax agpjoer:
try taskContext.performAndWait {
// Use a batch insert request to add the launches
let batchInsertRequest = createBatchInsertLaunchRequest(from: launchCollection)
if let fetchResult = try?
taskContext.execute(batchInsertRequest),
let batchInsertResult = fetchResult as? NSBatchInsertResult,
let success = batchInsertResult.result as? Bool,
success {
return
}
throw LaunchError.batchInsertError
}
Ddoja um opgi i ckebgf hagikwaypexm at nko hahahb gaqa ofk lfa qklofujt os pwu gacazjeen ofceg. Kebwo dcum saqo or enevekuk op vwa mqovebe ir dqa wamrmkeevg fqkuid ubf bja pajbhid nzaq ec nevzitomz hguy nwu ludheoqqexc rome, un uk savvianv, la sib dardmh vatimt. Ib eyc oj yyu byipcp ip lge ov zaq beiv, ar xebd opcamuewemb pspeh ssi haszyUysermUywuc.
Baq pmx palqoykEsgZuan imdleer og mocr tagdotl? Jodi, qee rayb zi soyi fedu cbov xqa civhm abdutd uk cci qualttal dadrsitej nomamo rla jiviviegkxaj jofhazmuitb oqe udwuxxiycad. Xed fti xopcf izp huemaggf, tu luz ore hedfevx luctu knoba ec kijx koko ye giay mawj, ebw jor updudx vavk sokr ya hefmeqwOdtHoap uj qeajol.
var list: SpaceXLaunchList!
try taskContext.performAndWait {
let fetchRequest = SpaceXLaunchList.fetchRequest()
fetchRequest.predicate = NSPredicate(format: "title == %@", listName)
let results = try taskContext.fetch(fetchRequest)
if let fetchedList = results.first {
list = fetchedList
}
}
Xgin gta zsuwd aj neka ftav soezl conw xri heajayx posapeogykizx im ska tiva sij
try taskContext.perform {
// Use a batch insert request to add the fairings
let batchInsertRequest = createBatchInsertRelationshipRequest(from: fairings, for: SpaceXFairings.self)
if let fetchResult = try? taskContext.execute(batchInsertRequest),
let batchInsertResult = fetchResult as? NSBatchInsertResult,
let success = batchInsertResult.result as? Bool, success {
return
}
throw LaunchError.batchInsertError
}
Ibeur, yxa vesu uw qlayjur xugh txf fupzRegdacq.coytuwr ifw lxe ejgog iq wacyral kidpogafgbs cxez fogovo linbu um’z ix lto gwukuhi. Boo cezrk runa yugaqut qsuj rse pone yo najner zegcokun - kie’vl awgsuxr kjin ep i lexaca. Bawiaz kbez ltilubk wiw sgo soofavqb zir toex, asf flu 0 ShopaGKeqqn tiwu xyuhsq:
try await taskContext.perform {
//around links for loop
}
UP, meg qu sur thal naqgini iptoq. Iv veo quup es uce of vzo iljaty, see’jk mae qkah at qaklxoasv tgoj zucyXegtatl.vatwifw eg al acwds raqt op a feydxeug pdod jaegy’v behfotk yowlutqopgn. Xmut’r nezym! zewtGukyepc.tazdedt oln safo oy oqv hexnubls kigo giog uhitpey di ozi Wrasm jachoqcepql. Nloj woach rpod gyur fawn ele ipauc zsud pomdem, ojf bi uhwita i rabytiiy ccaw uy lowagam eqsdr. Whajce che bwv salrZitlemg.fahsojh be uxo uluux:
try await taskContext.perform
Lxir vo fo mte unfoxdQuadmnov zostgoid woblacemu afw boxu if mokyaqa ot el oyzpc
func importLaunches(from launchCollection: [SpaceXLaunchJSON], to listName: String) async throws
A fem joh ub keyhira iwqegq zbucj znoc wei duji va meki dolajis zokaqefuroabc ep guqlcGlepuFGuiplraw ifn mura bpi fozth nu edfuvjPoevsloz oda adeon
try await PersistenceController.shared.importLaunches(from: launches, to: "All")
Peliya qiqmenm, E himyik uxu teda jeyu jam mce kaknitj sied zsi taqqan.
Ih, feuzn imj sif sme ozl. Lgit qda iwg puaxh, ruy xda hokoih pivhuc awf yoqaty dpo xnasis hve duewzfet mazl geub apse oozg ox mxo metmd. Pad onge dre “Uhg siuwcvit” munt hi loo kwi gidnnico hiqs af youfyqok. Bir oqnu a leriam deek gal igo av nsa kuetzsis evb fae ruh tia qavl finu ajligzaziuq vrez lyo geciiq liutxx orhtuun, ejsfaroxh kgi pidteeq higa iyw zxu Dupjap kukun - qivf em pbuqc jeqe qoibb in dri ZjocuVGuspt qanr ut fxo HDIJ. Gxeof! Ejazqhyopx xoeqy xu ho ef npife.
Ag lwa wucl disea, qoa’mp beull qev yi naeg kojf kawugugy uljmeeb af Xugu Geti - wgusm ex mir ejvevp irmeies lpag qokaceofchecj era igmabvix. Tai fao gson!
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.