❓How do I check language availability in SwiftUI? 💡Use SystemLanguageModel.default.supportsLocale() to check if a language is supported. Display the result to users since not all languages may be available. 👉Free #SwiftUI picture book at bigmtn.studio
Mark Moeykens
@bigmountainstudio.bsky.social
📕Free SwiftUI Picture Book: bigmtn.studio
❓How do I get session history in SwiftUI? 💡The session object automatically stores a transcript of all conversation entries. You don't need to manually store responses—they're added to the transcript as soon as processing is complete. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I stream responses from an AI model in SwiftUI? 💡Use a LanguageModelSession with a for try await loop to process the response in chunks, keeping your app responsive as data arrives continuously. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I combine values from the UI into a prompt for LanguageModelSession (AI model)? 💡You can use the PromptBuilder to combine multiple parts into one, making it great for including UI values like selections and responses. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I use a PromptRepresentable in SwiftUI? 💡Create reusable prompt templates. The Prompt builder's buildExpression function automatically extracts the prompt from your custom Prompt objects—no need to reference it directly! 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I guide the model when generating values for my SwiftUI properties? 💡Use @Guide with constraints like .anyOf(), .range(), .count(), and .element() to help the model generate acceptable values for your properties. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I use an Array in the Instructions builder? 💡You can add arrays directly into the builder and it will be handled for you. No need to iterate over the values—the buildArray() function takes care of everything! Super useful. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I prewarm a language model in SwiftUI? 💡Call the prewarm function from your session's onAppear modifier to load resources into memory before the user engages with the model. Time it when your app loads, a view loads, or a text field gets focus. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I create a tool for AI models in SwiftUI? 💡You need to conform to the Tool protocol and define a name, description, arguments struct with @Guide macro, and a call function that executes when the model uses your tool. 👉Free #SwiftUI picture book at bigmtn.studio
❓What's the easiest way to send prompts to the LanguageModelSession (AI model) in SwiftUI? 💡You can pass a string directly into the respond(to:) or streamResponse(to:) functions—no need to create a Prompt object. 👉Free #SwiftUI picture book at bigmtn.studio
❓Why does my model return different data than my tool? 💡The model processes tool output and forms its own response with that data. The model's output is a String, not the raw tool data structure. 👉Free #SwiftUI picture book at bigmtn.studio
❓How can I tell AI Transcript Entry objects apart? 💡The LanguageModelSession (AI model) keeps a transcript of prompts and responses. You can loop though it and do a switch on the entry type. 👉Free #SwiftUI picture book at bigmtn.studio
❓Can I use Limited Availability Checks in the Instructions? 💡Yes! You can use limited availability checks right in your Instructions builder. The Prompt builder has a special buildLimitedAvailability function that knows how to handle availability checks. 👉Free #SwiftUI picture book: bigmtn.studio
❓How do I check if Apple Intelligence is available? 💡Use SystemLanguageModel.default.isAvailable to check availability. If it returns false, display a ContentUnavailableView to let users know Apple Intelligence isn't available on their device. 👉Free #SwiftUI picture book at bigmtn.studio
❓How can I control the length of AI responses in SwiftUI? 💡Use the maximumResponseTokens parameter in GenerationOptions to limit response length. This lets you show users a preview before generating longer content. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I show when a session is processing in SwiftUI? 💡Use the session's isResponding boolean property to track when a prompt is being processed, then disable your button and show a loading indicator while it's true. 👉Free #SwiftUI picture book at bigmountainstudio.com
❓When should you prewarm the prompt prefix in SwiftUI? 💡Prewarm it right when the view appears using .onAppear, or when picker values change since they're used in the prompt prefix. This prepares your AI prompt ahead of time. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I set instructions for a language model session in SwiftUI? 💡Pass instructions into the LanguageModelSession using the instructions parameter with a string describing the AI's behavior and role. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I control spacing between rows in LazyHGrid? 💡Use the spacing parameter in GridItem to set the gap. You can specify different spacing values (40, 20, etc.) or omit it for a default value. 👉Free #SwiftUI picture book: bigmtn.studio
❓What is one way to format currency values in SwiftUI? 💡Use Text with .currency format parameter and specify currency codes like "USD", "EUR", "GBP", or get the locale's current currency with locale.currency?.identifier. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I create links with different button styles in SwiftUI? 💡Use the Link component with buttonStyle modifiers like .bordered and .borderedProminent, plus shape modifiers like .capsule or .roundedRectangle for beautiful, tappable links. 👉Free #SwiftUI picture book at bigmtn.studio
❓What is a quick and easy way to create color gradients in SwiftUI? 💡Every color has a gradient property that transitions from a lighter version to itself. Simply use .fill(color.gradient) on shapes like RoundedRectangle to create gradients. 👉Free #SwiftUI picture book at bigmtn.studio
❓Do I need Identifiable on my Generable object used in an array? 💡If using session.respond(to:), yes add Identifiable. If using session.streamResponse(to:), no—a stable GenerationID is automatically created for you. 👉Free #SwiftUI picture book at bigmountainstudio.com
❓How do Shared Modifiers work differently in Group vs VStack in SwiftUI? 💡In a Group, modifiers are applied INDIVIDUALLY to each child view. In a VStack, modifiers are applied to the entire container as one view. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I create multicolor SF Symbols in SwiftUI? 💡You can use the renderingMode(.original) to show the symbol's full colors or customize with .tint() and .foregroundStyle() modifiers. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I implement pull-to-refresh functionality in SwiftUI? 💡Use the .refreshable modifier on a List view. When users pull down, you can run code to update your data - like adding a new item to your array. 👉Free #SwiftUI picture book at bigmtn.studio
❓Can I use optional variables in my Prompt builder? 💡Yes! Use optional variables directly in your Prompt builder with no need to unwrap or check for nil. The buildOptional function handles optional values automatically. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I get structured data from an AI model in SwiftUI? 💡Use the @Generable macro on your response struct, pass it to the model's generating parameter, then access response.content property to display the structured data in your UI. 👉Free #SwiftUI picture book at bigmtn.studio
❓How do I optimize my language model for a fixed prompt? 💡You can prewarm your model with that specific prompt using the prewarm() function, which improves performance when you know the prompt in advance. 👉Free #SwiftUI picture book at bigmtn.studio
❓What's one way to format numbers as currency in SwiftUI? 💡Use the Text view with format parameter - Text(value, format: .currency(code: "GBP")) displays values like £12.34. 👉Free #SwiftUI picture book at bigmtn.studio