Build AI-Powered iOS Apps with Foundation Models Framework - Featured Image
Technology3 min read

Build AI-Powered iOS Apps with Foundation Models Framework

Apple’s Foundation Models framework brings advanced AI features right into your app, without needing an internet connection. With Apple Intelligence, your app can generate and understand text, summarize content, refine writing, and even carry on conversations. Everything runs on the user’s device. You can also generate Swift data structures using the @Generable macro and connect your own tools to expand what the AI can do. All it takes is a supported device with Apple Intelligence turned on.

Add on-device AI text generation to iOS apps

Apple introduced the Foundation Models framework at WWDC 2025. It allows developers to use AI-powered text generation directly on the device. No need for external APIs or internet access. Your app can process user data while maintaining privacy and avoiding API costs.

Examples:
  • A fitness app that names custom workouts.

  • A writing app that suggests phrases.

  • Any app that uses or creates text locally.

Check device compatibility

Make sure the device supports Foundation Models:

let systemModel = SystemLanguageModel.default

guard systemModel.isAvailable else {
    return
}

Check detailed availability:

switch systemModel.availability {
case .available:
    print("Ready to use.")
case .unavailable(.appleIntelligenceNotEnabled):
    print("Apple Intelligence is off.")
case .unavailable(.deviceNotEligible):
    print("Device not supported.")
case .unavailable(.modelNotReady):
    print("Model is downloading.")
case .unavailable(_):
    print("Unavailable.")
}

Start a basic text generation session

Create a session and send a prompt:

let session = LanguageModelSession()
let prompt = Prompt("Tell me a knock knock joke.")
let response = try await session.respond(to: prompt)

Output:

Knock, knock.
Who's there?
Lettuce.
Lettuce who?
Lettuce in, it's freezing out here!

Test in Xcode using Playgrounds macro

Use the Playgrounds macro to test prompts quickly:

import Playgrounds

#Playground {
  let session = LanguageModelSession()
  let prompt = Prompt("Tell me a knock knock joke.")
  let response = try await session.respond(to: prompt)
}

Continue conversations with multi-turn prompts

Reuse the same session for follow-ups:

let followUpPrompt = Prompt("Tell me another knock knock joke, but make it similar to this one: \(response.content)")
let followUpResponse = try await session.respond(to: followUpPrompt)

Write better prompts

Be clear and specific.

Not ideal:

Come up with a good joke about a baker whose latest attempt at a wedding cake went wrong.

Better:

Come up with a good joke about a baker whose latest attempt at a wedding cake went wrong. Keep it to one paragraph or less.

Set role-based instructions

Guide the AI’s behavior with instructions:

let instructions = Instructions("""
You are a comedian making food-related knock knock jokes. Keep them short and follow the classic structure.
""")
let session = LanguageModelSession(instructions: instructions)
let prompt = Prompt("Cheese.")
let response = try await session.respond(to: prompt)

Output:

Knock knock.
Who's there?
Cheese.
Cheese who?
Cheese move, I'm coming through!

Advanced features

  • Generation options: Control randomness.

  • Streaming responses: Get real-time output.

  • Structured outputs: Define formats with Swift macros.

  • Safety tools: Avoid unsafe content.

  • Tool calling: Connect AI to custom tools.

  • Memory: Track past messages in a session.

Conclusion

Apple’s Foundation Models framework makes it simple to add intelligent AI features to your iOS apps while keeping everything on the device. This means your app can stay fast, private, and secure without relying on internet access or external APIs. Whether you're building tools for writing, conversation, or custom content generation, the framework gives you powerful capabilities with minimal setup.

Posted on: 12/6/2025

hassaankhan

Frontend Developer — UI/UX Enthusiast and building scalable web apps

Posted by





Subscribe to our newsletter

Join 2,000+ subscribers

Stay in the loop with everything you need to know.

We care about your data in our privacy policy

Background shadow leftBackground shadow right

Have something to share?

Write on the platform and dummy copy content

Be Part of Something Big

Shifters, a developer-first community platform, is launching soon with all the features. Don't miss out on day one access. Join the waitlist: