Building an AI-Powered Health & Fitness App with Apple Foundation Models

07 / Apr / 2026 by Piyush Bharadwaj 0 comments

  What are Apple Foundation Models?

Apple’s Foundation Models framework marks a significant shift in how developers build intelligent applications on Apple platforms.

Instead of relying on cloud-based AI services, Apple now provides on-device large language models (LLMs) that are deeply integrated into the OS. These models are part of Apple Intelligence and are designed to work seamlessly with Swift, enabling developers to build powerful AI-driven features with minimal overhead.

Apple Foundation Models are:

    •  On-device large language models optimized for Apple silicon
    •  On-device large language models optimized for Apple silicon
    •  Privacy-first by design — user data stays on the device
    •  Low-latency and efficient, eliminating network delays
    •  Deeply integrated with Swift APIs, not external SDKs

 How It Changes App Development

  •  AI becomes part of your app logic, not an external dependency
  •  Prompts act like dynamic functions
  •  Outputs can be strongly typed Swift models
  •  You can build real-time, interactive AI experiences
  •  Apps work even in low or no connectivity scenarios (depending on availability)

What We’re Building

In this blog, we’ll build a Health & Fitness app powered by Apple’s on-device AI.

The app acts like a personal fitness assistant, offering:

  • Generate workout plans from natural language
  • Analyze workout history and generate insights
  • Suggest alternative exercises dynamically
  • Provide real-time motivational coaching
  • Fully on-device intelligent experience
App Dashboard

App Dashboard

Core Concept: LanguageModelSession

Every interaction with the model starts here:

let session = LanguageModelSession()

This session:

  • Manages communication with the model
  • Handles prompt execution
  • Supports structured and unstructured responses
  • Enables streaming for real-time output

Structured AI with @Generable

One of the most powerful features is structured generation:

@Generable

struct GeneratedPlan: Codable {
 var name: String
 var duration: Int
 var exercises: [GeneratedExercise]
}

And Nested structure:

@Generable 
struct GeneratedExercise: Codable { 
 var name: String 
 var sets: Int
 var reps: String 
}

Why this is powerful:

✅ No parsing required
✅ Guaranteed output structure
✅ Type-safe integration with SwiftUI
✅ Cleaner architecture

enerating a Workout Plan

Convert user input into structured data:

let response = try await session.respond( 
  to: prompt, 
  generating: GeneratedPlan.self 
)

let plan = response.content

// You can refine prompts dynamically:
let prompt = "30-min home workout, no equipment, beginner"

What happens under the hood:

  • The model interprets intent
  • Maps it to your schema
  • Returns a ready-to-use object
Generated workout plan

Generated workout plan

 

📊 Generating Monthly Insights

For text-based analysis:

let response = try await session.respond(to: prompt)
let insights = response.content

// Example prompt construction:

let prompt = """
Analyze the following workout logs and generate a summary.
"""

Useful for:

📈 Performance summaries
🧠 Pattern detection
🎯 Goal recommendations
💬 Personalized feedback

insights

insights with report

 

🔁 Exercise Substitution

Adapt workouts dynamically:

let response = try await session.respond( to: prompt, generating: SubstituteExercise.self )

let substitute = response.content

// You can guide the model with context:

let prompt = "Suggest an alternative for push-ups due to wrist pain"

Enables:

  • 🩹 Injury-aware alternatives
  • 🏠 Equipment-based adjustments
  • 🎯 Consistent muscle targeting
exercises

exercises substitution

Real-Time Coaching with Streaming

Streaming enables live AI interaction:

let stream = session.streamResponse(to: prompt)

for try await chunk in stream { text = chunk.content }

Why it matters:

  • ⚡ Immediate feedback
  • 🎯 Context-aware coaching
  • 🧑‍🏫 Feels like a real trainer
  • 🔄 Continuous updates
exercise motivation

exercise motivation

 

Model Availability

Always check before using:

let model = SystemLanguageModel.default

if model.availability != .available { // Handle fallback }

// Optional debugging:

print(model.availability)

Considerations:

  • Not all devices support Apple Intelligence
  • Simulator support may be limited
  • Always design fallback experiences

Architecture Highlights

  • 🧱 Dedicated AI service layer
  • 🔄 Reusable prompt patterns
  • 📦 Codable + Generable models
  • ⚡ Async/await for concurrency
  • 🎯 Feature-driven UI structure

Key Takeaways

  • AI is now native to the platform
  • Structured generation simplifies development
  • Streaming unlocks real-time UX
  • On-device models improve privacy and speed
  • No backend required for intelligent features

Final Thoughts

Apple Foundation Models redefine how we think about AI in apps:

  • No infrastructure overhead
  • No external dependencies
  • Seamless Swift integration

This is especially impactful for:

  • Health & Fitness apps
  • Productivity tools
  • Education platforms
  • Personal assistants
FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *