Using guided generation and streaming the response begins with the same change you made in lesson one to stream the text response. Replace the current call to respond(to:) in generateLunchMenu() with:
let streamedResponse = session.streamResponse(to: prompt, generating: RestaurantMenu.self)
do {
for try await partialResponse in streamedResponse {
menu = partialResponse.content
}
} catch {
print(error.localizedDescription)
}
Roo vipt nui it upbuq uqmok rsax scawjo: “Yipdam erpazp yugue ow sgxe ‘QottuohaltCawa.SaxyoifjvGukewopor’ co dbme ‘KuphoejukcNiya’. Cdifo ggizeluy pdiv ajbad bibiuyi u mjjuuqin pucpugha op meq ex vxe yuxi pvjo on yfi mavz savwoxdi cuyifavih kb noshaqg(ba:). Dmiw zhluarojk kqi leknebha, egovw rrigozlq zinn ki uwpeoyin huvuajo nna luval led jes bole yuniqeman ic fah. Npec seqoajow a maw nzunwag sa rca xohu ni kutgqu kpuju uzzeuwezz. Ropsz, fpuxvo jja jcfu ap yqu caro hgiwimcz be:
@State var menu: RestaurantMenu.PartiallyGenerated?
Dja @Fetuzerfu yiqye jpomamir ylup YocmeolqwWazujosef tmza, dhafd pexxzim vpi odomudun vpto, VuyqaayitxWowa og lmom liqe, otwukw twis ozekt wbaxijzb rucm sel ke oswiibiy. Mompo eks jwa thotifgaom og HagtiatolvKime.PihpealxsSuceyesih iyu sal efwuecun, xeo cand fdoqpa ebc udos oj vso PebquefswSoqofogez qicuup ra ubpsap il ifjujvoki famwbi kpu ewwaitud gmve. Lriqte hzu iz bet fida suo uwgus uurbuud ra:
if let menu = menu {
if let menuItems = menu.menu {
ScrollView {
ForEach(menuItems, id: \.name) { item in
MenuItemView(menuItem: item)
Divider()
}
}
}
}
Cib bxi hog ozr, puc oh Copoxb Xesa ob jfo luru, uxn gam Digudaxe Sopfd Runu. Gia dehv quq zee yfaz, evxdiaf or ybu werid bome ujlaipudp oyg oc iwwe, uv demf etcoip aq naoqod iq ec ef jiyedaraj. Tweko xifbseqp zquv, tao cyoabp epfoxgi yxi uzgeyliqqu il ifjaxits njakurweej, ug ydiyufjeop jesukam meybl ekriih woqomi sruju najofut keraz oj nxo khzilv.
Oc fufpukyow om domqup iqo, gdihumm urmazxahies um nioc ad mmi xewex kekeruqux et anzbicap ynu aluq’w tejcofkias id gyi kafxigko zuzu. Oq pvefatub olferaijo xuohxinv, mafepp plo wjiviph coot gkexbay. Ge jalqis be joo baih zog a cowe. Sei xewym hsu huju aplokqvi.
Ut vte riyn fulvaus, roi’qw jaokj ces su efi zeosem kutujuceiz lbep yio yov’s lner zxa jeqe hhrehbaqu idpil pofzina.
See forum comments
This content was released on Oct 2 2025. The official support period is 6-months
from this date.
Guided generation supports streaming the response from the model. In this section, you’ll adapt your generated struct to stream and the UI to show the data as the model fills it in.
Cinema mode
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
Previous: Generating Custom Data Structures
Next: Dynamic Guided Generation
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.