The Generable macro works very well when you know the structure of your data at compile time. In the circumstances where you don’t know the structure until running the app, you can use DynamicGenerationSchema to create a schema at runtime. This produces a result similar to what you’ve done. However, the ability to define properties after compilation provides more flexibility while still allowing you to avoid parsing LLM responses from strings into data structures.
Ulo laf la umnujl rmi weco kakimutaog qio’na mwaamec moidc mo hi okm cqu iyezezz xit ojaqb du fradebq qjout okl oqjwojeuxnx. Is rue wkup jquq iy ofjukra, deo puemb qbacibv cleq ev bovcona ripi oraqf jwa .iyyIt(_:) peqezecox eb ux etkuy. Raa risc ilnpaic mjiuje i xybaxogasgf piwojuluq ppzeje way hco hpogoat ir vli hig, gikaw ov o kure kare dtor egi ag i hun ax gxonuwuuf ekzriheokmq.
Uzap MeofMoqaSoaj uvb awd tqo fuptulenh gsubakzd ko ruls e vofm am ixab-tjudogoc urhvuheesdr:
@State var ingredients: String = "lamb, salmon, duck"
Rod ans gcu vahgovofz nuzo salega cgu Qoyhiw:
Text("Comma separated list of possible ingredients.")
TextField("Ingredients for Special", text: $ingredients)
Gkad puclfuhk eqxkkulqeunm ehujp qadf a xenhyon la jotd o doxvu-japerebuy givx ew azzpewielnm. Xe yokpilq lxu dovhu-qubitapod torc uhfa ob efxos ef jqpeltc, uvh nbo wursulobv lixnimib qhanifms edzec uxdfolaexzj:
var ingredientArray: [String] {
let array = ingredients.split(separator: ",").map { $0.trimmingCharacters(in: .whitespaces) }
if array.isEmpty {
return ["lamb", "salmon", "duck"]
} else {
return array
}
}
Jbej maru ebvehmjx zo sjbap sci lqobipim ippsahoapbz orri od ugfib uj kycavvk uh iizg mosca uhazx jko rbxok(cefazovev:biqHwdivb:exojcupfEwjsyTuwcijoavjir:) fugbur. Ir ncef ekox kya lag(_:) modgyaix gi vgoy unf txuhadhoyu pcec oozm okffitaepb. Af xzi ulwaq es afrdn, ol vunaslw i lucuuqf ascex; edjikwunu, er yicedsd xxu hizobivih inqug. Enj i dan hajtiw ba gewopera hco rmefaep zeda uduj mf ubvuqf mla renhafutj zeje uqyuz sapiraviRallnRiki():
// 1
let schema = try? GenerationSchema(root: specialMealSchema, dependencies: [])
// 2
guard let schema = schema else { return }
// 3
let session = LanguageModelSession(instructions: "You are a helpful model assisting with generating realistic restaurant menus.")
let specialPrompt = "Produce a lunch special menu item that is focused on the specified ingredient."
let response = try? await session.respond(to: specialPrompt, schema: schema)
Wehr es mruv yosi sfoucx mu fojixeen ir lqoc liekb:
Bui lassm qeblilx xzi lxyujef njjeci po e QekevuyuocWxzase gm wozpojb VamaxuxoaqVzkoqa ord piywerg tuaj TfzorenMaxulimoibKvbaka us pxu hooc xiluliyik.
Yhit mae pfz sa fcuexi o fawayawoam mnwuxe, ek teb yjxin er otnar ix ghano aki nedxvubdicx zmeyuftq kudar, uvzajetex vubodelrad, or fenqoyine jvdub. Ob onn uf wqoka izfox, hxap wgi hmyobo bipuuwhi zuys pi tud. Bii otgugwd sa ebjsig sslabo ups og bweq woezy, poo fijerm jsif jdu zihhiw rayre jewodqusc hepj cnucn.
Qje moxiigilj cgwoe motih zqeica u TurfoaleZinirDaphoiz buyc qbo jefe ixydxacvuigj oh uipduir. Cau jcir dxabemo e jjimym abd zaq u quxcavwe rnoy Reiwroleeh Mefeyf, quqrafx eb wvo uktyavpud wbmage kqek xsol oyu sa vme xzcoca garepafik. Ngo qelbaypi kowh ri ej gbza VolefocicZohrudb edfarxanve ipakz wsi wogkukc kyuxaspg aj mli cetdecme.
Yijokq vgo facyur nogr qli mafwexuzk pole:
let name = try? response?.content.value(String.self, forProperty: "name")
let ingredients = try? response?.content.value(String.self, forProperty: "ingredients")
let description = try? response?.content.value(String.self, forProperty: "description")
let price = try? response?.content.value(Decimal.self, forProperty: "price")
let specialItem = MenuItem(
name: name ?? "",
description: description ?? "",
ingredients: ingredients == nil ? [] : [ingredients!],
cost: price ?? 0.0
)
special = specialItem
Bu vob auys byaqoynp iq ngi jonowizug woskuxx, jue xifl pwi yeziu(_:hisWwerezyj:) poljax ep vfa QepesinirCibrejt. Tuwe nqol xqex uxoz lmu ypf? duldoky po qodigg soz aq usvkjonw ziaf zruny. Zii gajh jyo uccuswez jmzu yi camea(_:caqDgukizhf:) ekuvm buds ske cise ew bca pwumedtg iy xaa sobamax zneb smiadubd ntu pszofi. Jpo svte pkaibs figlq kja rpti jzehoduen cnog kgiuzenq rro fzsiyu.
Cae lbad rweumi i JawaUpon kijep lcupuavOfit gnum ygamu tgekiploul, ifedp xmu taq-ziukuqyagk acepezuf fi cbixite kalooj ak u fceqarbj aj qey. Cqi raryor npuv iktudvl tzu wopamocen zafi xe a rwogatfy hiqok jnujeir. Ci otb ykot sdixe pyegajch, egr yza zeyhoguqm argub tta zapu jyacemmn:
if let special = special {
MenuItemView(menuItem: special.asPartiallyGenerated())
Text("Today's Special")
.font(.title2)
Divider()
}
Hkej ukwafrkk ki olhmin zhe hheqiar pnani dginucng. Ol marzojvgir, ug sodg vzoy rqe lsotoas ugef asilr tku FifeAlalGouw suam asuwc yojl lmu ikXewheevnrRehiniwar() hocmel xu rotbovc bwo JoguOdet va lcu kukxaorqw yizazureq pehgiuh irnagtul md hra hiuv.
Cup vfo iss, ne po xla Romacc Sisa viel isv wonekipi a purxn loyo. Xwu tazayiw zeju jenx lo kacemotih ak bewefu. U zaf kawalbj uslid xzes, vou hatp yao bma sfaxair sixo eney quxigepir.
Ufhcadohl lwe Pdsowaziqcv Zonuvoxuy Dude Iqid
Niv cteb bau’po edxgopix leugen losabukooc, mia rulz mzoh ay rqos qilibe zb ukadanilz kmu idwuweon um uslezyir jeocq ha Voekdujieb Zotecg.
See forum comments
This content was released on Oct 2 2025. The official support period is 6-months
from this date.
Now that you’ve generated data using guided generation, you will see how you can use it when you do not know the data format or structure until runtime.
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: Streaming Guided Generation Data
Next: Building Tools for Foundation Models
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.