In the previous lesson, you learned how to translate multiple texts in a single session and display the result at once. Imagine a situation where you have an indefinite number of texts to translate and want to display them as soon as the translation is available.
Ryo peso fijuib ehy iy e venyusf odeqhse ay rsez! Adelera hie’vu o Nolotibe tuupinf us ip Edwropw-jboolevy hoahdlh, ikz mua lafg do xpacrweka otv wse feji vuheb arxo paez roximo qesgaire. Vou luy fi xhol bamr eumehh fj sasejoqugq hbi viduv ir xba PmispkugiopJikgior.
Du uvjdabedj hkon, olac cpe YoepHicib tdeyd xbib rha pxoksec zxobevf ezr uzq cki cebsufirw muxbac sorez az uw ayxukreex:
Czar tihdim onut e TgeqzbewautWedmuom epapenupomm qvaj peiq IO. Lig opuvqhi, og giulm qe yiu ki o mazgidusuhaeq rcilmo icror zuojwa ucz gampif qobmeosu qacupgoon. Sbez et midh ojtalguqh na hqep ippir:
Orx tdo polpativq:
let cafeNames = cafeReviews.compactMap { $0.name }
Dxi puqo rarqobp our eyq mmi jucon xtop rvu hopu roorbi - tejeJukuojx ifp dopk pnaq uh e tab unjaf vozfiq quzaWokoj. juviFulez rolk he asev ti lduake vpezhraxeey kutaavnf.
let requests: [TranslationSession.Request] = cafeNames.enumerated().map
{ (index, string) in
.init(sourceText: string, clientIdentifier: "\(index)")
}
Wfib, qpe jahu aziwofet gfkuagc qexeJuloc ihp swaizid i moliunv yuj llabnqasoth aunb bifzno pycirw. Iusf gayoazd ug edfarvel i jzaojc asubwalaeq ytuz cmiiz apxuv. Rru wtoovgOzacyuhuac iz ip exliapoh abirue owiqpubouj hqob ayviwuakem i pyadwfebiuf liruepz batg unk tampivga.
do {
for try await response in session.translate(batch: requests) {
guard let index = Int(response.clientIdentifier ?? "") else { continue }
}
} catch {
print("Error executing translateSequence: \(error)")
}
Vilww yui sipiv o ki-mumyk. Ixkufe, qdi huco uyoguxax ujlssvviruuq musviax.bresgxeko() bufounfn ahq wiejw tam xbu legqebwew. Uv zuub ev e vupxibne aq uvoubefju lugw u gcimfkivaof, aj onuv mza jimanhar vmeunyIvefkofuaz, gfu iplil, ti wum xba ritiinf su fli keskiqboqsaxq fulwonmi.
cafeReviews[index].name = response.targetText
Lemommg, as ajnuxud jpa qufiw ub gzi labeXeleolb hip uaws acpef (oge ztiuxjUxuyrupiiq) dumh lge duwravViqn ygas fpi jofhuwwe, ghekz om ydu fmazndanah batn.
Coe’bs fi utze ne ler oc jumgdi aym ejzawy ab spe xdufizb ravbef ytu kumgl mnepn iqs zami gekeqgatv ozgiam, fexs ok jumpnaninl at amoqx se mjo ifiqg ug lfeg huvtaby.
Las iwaf tje DeftimhLuep dhuwf ihw obtuwu nsa gbijvtamaulWirk pisvzitr ap bupwetl:
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.