Xcode Playground and FoundationModels

I am trying to test FoundationModels in a Swift Playground in Xcode 26.2, macOS 26.3, and am running into an issue. The following simple code generates an error:

import FoundationModels

@Generable
struct Specifications {
    @Guide(description: "Search for color")
    var color: String
}

I see the following error message in the console:

error: AIPlayground.playground:4:8: external macro implementation type 'FoundationModelsMacros.GenerableMacro' could not be found for macro 'Generable(description:)'; plugin for module 'FoundationModelsMacros' not found

The Xcode editor does not appear to recognize the @Generable or @Guide macros, despite importing FoundationModels. What step/setting am I missing?

Answered by Apple Designer in 877092022

Thanks for reaching out!

To clarify, Foundation Models framework is currently not available in Swift Playgrounds, which you get if you do Xcode > File > New > Playground... Overall Swift Playgrounds only support a subset of the SDK.

Foundation Models is supported in Xcode inline Playgrounds though, so if you do:

import Playgrounds
import FoundationModels

@Generable
struct Specifications {
    @Guide(description: "Search for color")
    var color: String
}

#Playground {
    let session = LanguageModelSession()
    let response = try await session.respond(
        to: "Help me search for orange", 
        generating: Specifications.self
    )  
}

This should work.

Accepted Answer

Thanks for reaching out!

To clarify, Foundation Models framework is currently not available in Swift Playgrounds, which you get if you do Xcode > File > New > Playground... Overall Swift Playgrounds only support a subset of the SDK.

Foundation Models is supported in Xcode inline Playgrounds though, so if you do:

import Playgrounds
import FoundationModels

@Generable
struct Specifications {
    @Guide(description: "Search for color")
    var color: String
}

#Playground {
    let session = LanguageModelSession()
    let response = try await session.respond(
        to: "Help me search for orange", 
        generating: Specifications.self
    )  
}

This should work.

That works! Thank you.

Xcode Playground and FoundationModels
 
 
Q