Skip to content

[google_sign_in] PR 4/4 Convert the Pigeon host API from Objective-C to Swift - #12658

Open
victogomez-cs wants to merge 4 commits into
pr3/google-sign-in-ios-view-providerfrom
pr4/google-sign-in-ios-swift-pigeon
Open

[google_sign_in] PR 4/4 Convert the Pigeon host API from Objective-C to Swift#12658
victogomez-cs wants to merge 4 commits into
pr3/google-sign-in-ios-view-providerfrom
pr4/google-sign-in-ios-swift-pigeon

Conversation

@victogomez-cs

@victogomez-cs victogomez-cs commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Converts the Pigeon host API from Objective-C to Swift (swiftOut / messages.g.swift) and implements GoogleSignInApi with throws/Result instead of Obj-C error pointers.

Generated Swift is committed codegen from pigeons/messages.dart (Pigeon 26.3.4), then swift-format. messages.g.h / messages.g.m are removed. The Obj-C SPM target’s publicHeadersPath is narrowed to the remaining Obj-C headers.

Missing-presenter failures from PR 3/4 are returned as PigeonError. Tests updated for the Swift Pigeon types.

Bumps google_sign_in_ios to 6.3.5.

PR 4/4 of the Obj-C → Swift migration. Depends on PR 3/4 (ViewProvider / GID wrappers). Completes flutter/flutter#119103 for the iOS/macOS plugin implementation.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 27, 2026
@victogomez-cs victogomez-cs added triage-ios Should be looked at in iOS triage and removed CICD Run CI/CD labels Aug 27, 2026
@google-cla

google-cla Bot commented Aug 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@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 migrates the Pigeon host API for the iOS Google Sign-In plugin from Objective-C to Swift, replacing the autogenerated Objective-C files with Swift files and updating the plugin implementation and tests accordingly. Feedback on the changes suggests using the any keyword for existential protocol types to align with modern Swift standards, replacing an Objective-C style string formatting initializer with a simple string literal, and avoiding force-casting in tests to prevent potential test runner crashes.

Comment on lines +102 to +105
let signIn: GIDSignInProtocol

/// A mapping of user IDs to GIDGoogleUser instances to use for follow-up calls.
var usersByIdentifier: [String: any GIDGoogleUserProtocol] = [:]
var usersByIdentifier: [String: GIDGoogleUserProtocol] = [:]

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

To maintain consistency with the rest of the codebase (such as GoogleSignInTests.swift) and ensure readiness for Swift 6's strict existential type requirements, please use the any keyword when referring to the existential protocol types GIDSignInProtocol and GIDGoogleUserProtocol.

Suggested change
let signIn: GIDSignInProtocol
/// A mapping of user IDs to GIDGoogleUser instances to use for follow-up calls.
var usersByIdentifier: [String: any GIDGoogleUserProtocol] = [:]
var usersByIdentifier: [String: GIDGoogleUserProtocol] = [:]
let signIn: any GIDSignInProtocol
/// A mapping of user IDs to GIDGoogleUser instances to use for follow-up calls.
var usersByIdentifier: [String: any GIDGoogleUserProtocol] = [:]
References
  1. Code should follow the relevant style guides and language idioms for Swift, which includes using existential any for protocol types to align with modern Swift standards and prepare for Swift 6. (link)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Marked the GIDSignInProtocol / GIDGoogleUserProtocol existentials with any on the stored properties and the matching init and method parameters

completion(
.failure(
PigeonError(
code: String(format: "%@: %ld", "(null)", 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.

medium

In Swift, we can use a simple string literal "(null): 0" instead of the Objective-C style String(format:) initializer for better readability and performance.

Suggested change
code: String(format: "%@: %ld", "(null)", 0),
code: "(null): 0",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, those format arguments were constants, so the literal is equivalent. Updated to "(null): 0"

Comment on lines +537 to +540
// Unexpected errors, such as runtime exceptions, are returned as
// FlutterError.
let flutterError = error as! PigeonError
#expect(flutterError.code == "google_sign_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

In Swift Testing, using force-casting (as!) can cause the entire test runner to crash if the cast fails, preventing other tests from running. Instead, use try #require(error as? PigeonError) to fail the test gracefully. Additionally, update the comment to refer to PigeonError instead of FlutterError since the API has been migrated. Note that this same pattern of using as! and outdated FlutterError references occurs in several other places in this file (e.g., lines 639, 732, 755, 854, 886, 945) and should be updated similarly.

Suggested change
// Unexpected errors, such as runtime exceptions, are returned as
// FlutterError.
let flutterError = error as! PigeonError
#expect(flutterError.code == "google_sign_in")
// Unexpected errors, such as runtime exceptions, are returned as
// PigeonError.
let pigeonError = try #require(error as? PigeonError)
#expect(pigeonError.code == "google_sign_in")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the comments to PigeonError and dropped the as! casts so a type mismatch fails the test instead of crashing the runner.

I didn’t use try #require here: these assertions sit in a non-throwing completion, so try doesn’t compile, and a thrown #require would skip confirmed() and hang the test. Used guard let … as? PigeonError so confirmed() still runs

@victogomez-cs
victogomez-cs force-pushed the pr4/google-sign-in-ios-swift-pigeon branch 2 times, most recently from 199a0af to 5b3567d Compare August 27, 2026 20:56
… for missing presenter.

Refactors the sign-in method to handle errors more robustly by switching to a result-based approach. This change ensures that when no presenter is available, a PigeonError is returned, allowing for better error reporting in the Google Sign-In process. Updates existing tests to verify the new error handling behavior.
@victogomez-cs
victogomez-cs force-pushed the pr4/google-sign-in-ios-swift-pigeon branch from 2413466 to 287290e Compare August 28, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant