reports icon indicating copy to clipboard operation
reports copied to clipboard

FB18559986: Suggestion to improve foundation models sample project

Open malhal opened this issue 5 months ago • 0 comments

Submission Date

2025-07-02

Status

Open

Area

Documentation

Operating System Version

iOS 26

Type

Suggestion

Description

Sample Code https://developer.apple.com/documentation/foundationmodels/adding-intelligent-app-features-with-generative-models

Hi I'd like to suggest a small improvement to this sample project, in FoundationModelsTripPlannerApp.swift instead of:

struct FoundationModelsTripPlannerApp: App {
    private var modelData = ModelData.shared

    var body: some Scene {
        WindowGroup {
            LandmarksView()
                .environment(modelData)
        }
    }
}

It is preferable to delay loading the model until body is called. So it won't be called during Previews which need all the help they can get to launch quicker. E.g.

struct FoundationModelsTripPlannerApp: App {

    var body: some Scene {
        WindowGroup {
            LandmarksView()
                .environment(ModelData.shared)
        }
    }
}

In Previews although the app struct is init and thus all of its properties are init too but the body is not called so expensive model object init should be delayed until body.

I'm trying to submit edits like this to all the samples so they all can be consistent and help developers to get it right. Thanks

Keywords

sample code

Prerequisites

  • [x] The title follows the format FB<number>: <title>
  • [x] I will keep this issue updated with Apple's responses

malhal avatar Jul 02 '25 17:07 malhal