[google_sign_in] PR 4/4 Convert the Pigeon host API from Objective-C to Swift - #12658
[google_sign_in] PR 4/4 Convert the Pigeon host API from Objective-C to Swift#12658victogomez-cs wants to merge 4 commits into
Conversation
|
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. |
There was a problem hiding this comment.
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.
| 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] = [:] |
There was a problem hiding this comment.
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.
| 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
- Code should follow the relevant style guides and language idioms for Swift, which includes using existential
anyfor protocol types to align with modern Swift standards and prepare for Swift 6. (link)
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
Agreed, those format arguments were constants, so the literal is equivalent. Updated to "(null): 0"
| // Unexpected errors, such as runtime exceptions, are returned as | ||
| // FlutterError. | ||
| let flutterError = error as! PigeonError | ||
| #expect(flutterError.code == "google_sign_in") |
There was a problem hiding this comment.
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.
| // 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") |
There was a problem hiding this comment.
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
199a0af to
5b3567d
Compare
… 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.
2413466 to
287290e
Compare
Converts the Pigeon host API from Objective-C to Swift (
swiftOut/messages.g.swift) and implementsGoogleSignInApiwith throws/Resultinstead of Obj-C error pointers.Generated Swift is committed codegen from
pigeons/messages.dart(Pigeon 26.3.4), thenswift-format.messages.g.h/messages.g.mare removed. The Obj-C SPM target’spublicHeadersPathis 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_iosto 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
[shared_preferences]///).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-assistbot 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
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