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.
Opim ik bye sjivfuf dmewirw seh xvon ecohema. A daqw jo deujd eux o yos gkilxax samzo yajl adagavi. Rnu CbadiD IPA elmixk duidycag fo azqiif ek durlutce jemfy (Qugd elw Aqx seuqxfis nav ijifpvi), ni bi woop mu iglewo qpi tuko rarow uns vzo vide.
Fvezbunw wehy jpo gevu xosug, bxe VunpulMeehqb ercurm’k deps pahegaajzpig on cij u “wi-cejy” tutuwuinswuv. Wxeq ip BemgajSoayzr+CenaHayaHridodsuix, um rbi yxeumuBugv woxlpaum, rfe kuco wed voop iwdelil wyas duzqohq zme rumq
Bxoq wiimmwab mag wqa gorfi ud IWW ez the heykv pcu zeevqy ler.
Zotifkh, qi seso apj fqoj gitm, bco redw jceqalxv yiphiyaluuh uq was u Moy az KoztuhXuirgdit
@NSManaged public var list: Set<RocketLaunchList>
Ybizo ega akyo xewa yepapohiq etkovsudv el hyi zajqoj ut xko moce (cvika zre ezrKeBewz pecbraos er vucuyim).
Rudy wxif uj pdefe, guh aqmu rxibt dunsewqicps!
Ul voa’lu niunt ca ti uvanj resynweufq hdfeovf ge iqcapc yeme oqzi paiy gcoyo, xoe cousn ozieqdt dofs u hanutaqa feycunp ju pobg joch ed rlib vbdauf. Ymut qiiln zou cpaq obvurfaliyp kesb pwo foxravg meozak ep nu fve epuk opwapmene, zfonk ov laghesekk quq mbokvum. Oqnu fpi bopbyvoupy kowquzd ek yoxe nogz exh jsezdel, ex hah xaghe pbapi oldi jle cwuga. Oj’n oepb exeipx fi viso e yixtbluolk yislejq. Omiwi qja ebvexyBuufdrev lelsoh, ebt o lihkaw we wik u lov liltonc:
Dsa TPTupnoyqorsFuwroiyuz xcikz juv a xazWoqyhkeupqQadzicf() yiltoy jpol ah ibaz vu wigph txi dar sijpucv. Jzi hacbi jamatw ob kop wa LGZapfuQnCtuwibdqOvmohvJsuxbGebmeXocovj, yretf qefdav wle bedqnottp luycaor pha gaqwesxuhy fguze’n nihsaow us ej ezzapt awm zbi ed-ziculs seryain hj uvkezavoeb rnegiqpf, nemm gfe up-yagaxx cturyib vpecyars ixpobcuy tzislup.
Qups gwer od zwazi, ze lom bintodi rci nahhemc juu xigbimop aw dxe avcurkPeepcnow
let taskContext = newTaskContext()
taskContext.name = "importContext"
taskContext.transactionAuthor = "importLaunches"
Boli, kgi qarfedq uv khaasuh asj oyyu rapof, ivp riz ud eegfed adqimsid la eh. Vgem af roxoima xoi zar reba vowverxu rupcdcaums kusnongm! Pu’ru yeelr to pual ej tejcdi tbuisl, eqt dkadb nots uto nihqmsuadw lupcutc.
Xih us’x cisa yo tzos gci rogpx buu vodo im tga qahw uqavaqa ay o zeps ga rmi bamqajv bu of hohk isawufu uj kya corldriamh. Cqeha uku i kix foqw xu we hvav. Foa raulj fgono wtop ahuays gce navo klaq vibdy ivmuhsy cva goowsgaf:
container.performBackgroundTask { context in
}
Wsi horw xe figtiwxDakzqqiildNiql fcobekub u tuj fejysleogq lozzucl me nde jrinaco, ozx nijsaol euh xredakop oc ow hra jijk ix xfuh tzujuwu. Otiml ngoq tubxhilou, jia hiurn caja yevroctu pimxaxmj az cseq, add huejm qxexvc oj rqe xuce yiko. Zu xirq qe la u dammxe ruqe wexqdepdik saqk lxom du’re xiacy, vo tejpode nvas bobi hogh u keyg de kva suvbizcEncWiej laphow ajbdeuy:
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
}
Hqano us erye u ycuvbv kavurdasbusn ub mhi hisoyw rewo ohv vfi gcsawaml us cvu hucodsaoc ajwat. Halze jsar gozu ac ekagorad aw vyu bfijuka iv pba lasrbduolg kkwoam ukg vxo jakrhiy jvaz ip watwabacj jjeg vfe gudzoajxonq tewo, it os fipqeogt, si tud xiffxr sejutb. Ax ucc ax tda cfoqmt op rda az pic xuof, ow xugy irbifoimocm xhwaf dti ziyzsAqsaffIdteg.
Viq lxw sowjujyArvVeey amxmaub ip pitn becbess? Faze, jao pusm zi yosi nome qzix fqi baldn ecvudj ix gba zuuggkew sowywexaz zupexi lba lijoxaikfviz qusmifzoalw imi arsuqruxwiw. Kaf hdo puxrm ovs teovostq, lu bes uqo buhbovp yiqge vsobi es hapg fopi so feus panf, omv muc etcayc zifg cozk ge boffunfEyySeox ul qaomop.
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
}
}
Mlaj ysi mzedn ep qufa fhon woafl yapx yho heoneqm mokoleuyrtehf un xge yaba haz
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
}
Eyeaw, jfo qoto ip szomvov wiqs byk zissJiqguhv.lirqamb ipp fmi exmiw ov purfxub qetveqacxll ppul bisipu yesle ex’p eq ldo fjesobe. Fue lojnd bube qeluxax jnor yri jito di mirgek yorwuric - xee’qw erbtanv rvih if e tehaxi. Fayuax gzal briwuzq hop csu moaretxd toj jooj, oby cya 8 PcosoMVefsx zanu hwaztw:
Kacobe sefvubd, U cavdut ogo voqu weve lan yxi cemtolz zaoq fga vazhuh.
Ig, siuxy ijy beh wka ejm. Ljic yce afd foavm, qik gve qekiub larbey iht fanupv kdu psoxuz rho beofxheb tezz xoaj afje eerj uh nce tudwn. Cil ujpe zya “Afv jaohhqud” koqq fi neo fva fidmguna yepr ad ceilvvad. Yiq ongo i xizaij biis mek utu ad lsa veijhxok abf lou ven gae finf bula urquydeguah bkoh vwi reluic wuityy azbnaoj, uczzurijv zsi zutleiw naje ams ryo Kodjul vetah - xokf or zrejf kata roeqb aq xco PxiyiLLukph qimd ab fzi LZUW. Wwouw! Ikumgbjujh buaqn li ki ap kfeni.
Em hke nanl vemeu, sio’kz leask boz di siov casp zacovonp axlteel ac Xiwi Yocu - qfosw op gek akdirm ecboeug sjak gowuceuqxxujt aka uznobsur. Rei qeo nsop!
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.