Skip to content

Instantly share code, notes, and snippets.

What is Foundation Model?

In simple terms, this framework gives your app direct access to Apple's powerful on-device Large Language Models (LLMs).

Think of it as having a private, secure, and fast version of ChatGPT or Gemini built directly into the OS that your app can talk to. The key differentiators are:

  • On-Device: The models run directly on the user's iPhone, iPad, or Mac. This means it's incredibly fast (no network lag), works offline, and is completely private. User data never leaves their device for these on-device models.
  • System-Integrated: It's deeply integrated into the OS, aware of system resources, and optimized for Apple Silicon.
  • Structured Output: This is a killer feature. You don't just get back a string of text. You can ask the model to respond with a well-formed Swift struct or enum that you define. This makes using the model's output incredibly reliable and easy.
@Asheshp23
Asheshp23 / SwiftUI ContentView with Password Validation.swift
Created November 26, 2024 15:33
SwiftUI ContentView with Password Validation
struct ContentView: View {
@State private var password: String = ""
@State private var isPasswordValid: Bool = true
@State private var passwordValidationMessage: String = ""
var body: some View {
VStack(spacing: 20) {
SecureField("Enter Password", text: $password)
.padding()
import SwiftUI
// MARK: - Data Models
// Struct for representing a student
struct Student: Identifiable {
let id = UUID()
let name: String
let age: Int
let grades: [Double]