Skip to content

FMF support#1855

Draft
peterfriese wants to merge 3 commits into
mainfrom
peterfriese/firebase-ai/quickstart
Draft

FMF support#1855
peterfriese wants to merge 3 commits into
mainfrom
peterfriese/firebase-ai/quickstart

Conversation

@peterfriese

Copy link
Copy Markdown
Contributor

No description provided.

@peterfriese peterfriese marked this pull request as draft June 9, 2026 16:55

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces integration with Apple's Foundation Models (Apple Intelligence) in the Firebase AI Example app, adding a new "Apple Intelligence" feature screen, a custom local places tool with Google Maps grounding, and a view model to manage hybrid summarization, planning, and visual identification. The review feedback highlights several critical improvements: correcting the iOS availability annotations and checks from future versions (iOS 26.0/27.0) to iOS 18.2, using array indices instead of optional properties as identifiers in SwiftUI ForEach loops to prevent rendering bugs, and refactoring the custom tool into a Sendable struct to ensure concurrency safety.

Comment thread firebaseai/FirebaseAIExample/ContentView.swift
import FoundationModels
import FirebaseAILogic

@available(iOS 27.0, *)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The availability annotation uses iOS 27.0. Please update this to iOS 18.2 to match the actual OS version where Apple Intelligence and FoundationModels are available.

Suggested change
@available(iOS 27.0, *)
@available(iOS 18.2, *)


// Day Plans
if let days = itinerary.days {
ForEach(days, id: \.title) { day in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using an optional property like title (which is String? in DayPlan.PartiallyGenerated) as the id for ForEach is unsafe. During streaming or partial generation, multiple elements might have nil or duplicate titles, leading to rendering bugs or crashes in SwiftUI. Using days.indices with id: \.self is a safer approach.

                        ForEach(days.indices, id: \.self) { index in
                            let day = days[index]

.padding(.top, 4)

if let activities = day.activities {
ForEach(activities, id: \.title) { activity in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the optional title property as the id for ForEach can cause duplicate identifier issues during partial generation. Using activities.indices with id: \.self is safer.

                                    ForEach(activities.indices, id: \.self) { index in
                                        let activity = activities[index]

Text("Sources & Maps Links")
.font(.headline)

ForEach(attributions, id: \.url) { attribution in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using the optional url property as the id for ForEach can cause rendering issues if multiple attributions have nil or duplicate URLs. Using attributions.indices with id: \.self is safer.

                            ForEach(attributions.indices, id: \.self) { index in
                                let attribution = attributions[index]

}

@available(iOS 26.0, *)
public final class FindLocalPlacesTool {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since FindLocalPlacesTool has no mutable state, declaring it as a struct conforming to Sendable is more idiomatic in Swift and safer for concurrent execution. This also avoids the need for @unchecked Sendable on its wrapper.

Suggested change
public final class FindLocalPlacesTool {
public struct FindLocalPlacesTool: Sendable {


// Struct wrapper to conform to FoundationModels.Tool AND ToolRepresentable
@available(iOS 26.0, *)
public struct FindLocalPlacesToolWrapper: FoundationModels.Tool, ToolRepresentable, @unchecked Sendable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If FindLocalPlacesTool is updated to be a Sendable struct, the wrapper can conform to Sendable directly without needing @unchecked Sendable.

Suggested change
public struct FindLocalPlacesToolWrapper: FoundationModels.Tool, ToolRepresentable, @unchecked Sendable {
public struct FindLocalPlacesToolWrapper: FoundationModels.Tool, ToolRepresentable, Sendable {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant